2

I'm working on a D8 project and I have some ajax callbacks where I use ReplaceCommand and HtmlCommand.

It works fine but adds an extra div to my html.

For example I do :

$response->addCommand(new HtmlCommand('select[name="field_expert_name"]', $options));

And in my select, instead of getting just the options, I get :

<select>
  <div style="display: block;">
    <option value="1">Val 1</option>
    <option value="2">Val 2</option>
  </div>
</select>

Is is possible to get rid of this extra div?

Thanks in advance!

3
  • See this issue drupal.org/node/736066. But why not replace the complete form element? Which is btw. necessary for other reasons too. When you want to submit the form without errors, include the select in the form build/alter. Then you can send the processed select element in an ajax callback.
    – 4uk4
    Aug 21, 2017 at 13:25
  • 1
    No, this is a known issue that is nowhere near fixing. you just have to use wrapper with some random id and then unwrap it.
    – user21641
    Aug 21, 2017 at 13:29
  • Thank you both for the response. @4k4 the field I try to alter doesn't belong to this form. I'm returning the form element in other cases!
    – Ismini
    Aug 21, 2017 at 13:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.