0

I've tried all options to trigger an ajax event on change of a selectbox option inside form alter hook, but nothing works. Below is the sample code

$form['field_select_box']['#ajax'] = 
   [
     'callback' => 'toggleOptions', 
     'event' => 'change', 
     'wrapper' => 'edit-field-target'
   ];

If I just try to attach the ajax event to a simple text field (like title), it WORKS.

$form['title']['widget'][0]['value']['#ajax'] =
  [
    'callback' => 'updateSubdomain',
    'disable-refocus' => FALSE,
    'event' => 'change',
    'wrapper' => 'edit-field-subdomain-0-value',
  ];

Help is appreciated

1 Answer 1

0

For select list, the ajax should be

$form['field_select_box']['widget']['#ajax'] = [
  ...
];

and please try to code as Drupal standard.

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.