0

I am trying to update some field options in an inline entity form with ajax. This should happen, when someone selects a value in an other field.

I already have some code which "works", but the problem is that you can edit multiple items and there seems to be a problem with the wrapper_id, because it is for all items the same and the entityForm function is called multiple times.

So what is the best way to do this?

0

What about adding wrappers to the fields?

In your hook_form_alter:

$form['field_name']['#prefix'] = '<div class="last">';
$form['field_name']['#suffix'] = '</div><div class="clearfix"></div>';

Check https://www.webomelette.com/drupal-form-api-prefix-suffix

  • The problem is that you can edit multiple items at the same time and so every item has exactly the same wrapper. In the ajax callback you than can't detect the right one. – Chris4783 Jun 22 '17 at 4:42
  • If you add prefix and suffix with id, they won't have the same wrapper. – Ismini Jun 22 '17 at 8:02
  • When I would add this code, all the items will have the same prefix and suffix, but for replacing to work, jQuery needs an unique selector. – Chris4783 Jun 26 '17 at 4:43
  • Yes, this was an example. The prefix should also have an id which will be unique for each field. You have the field name, so you could add : $form['field_name']['#prefix'] = '<div class="last" id="' . field_name . '-wrapper">'; for example – Ismini Jun 26 '17 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.