I have a simple ajax form with select form input:
$form['children']['number_children'] = array(
'#title' => t('Počet detí'),
'#type' => 'select',
'#options' => range(0, 15),
'#default_value' => $number_children,
'#ajax' => array(
'callback' => 'ajax_callback_registration_children',
'wrapper' => 'children-div',
'method' => 'replace',
'effect' => 'fade',
),
);
When the select input is changed manually it properly executes an ajax and appends new inputs into the form. But I need to trigger the ajax callback by javasrcipt code that is changing the selected option:
$('#children-div select[name="number_children"]').val('3').change();
This changes the value, but the ajax is not triggered at all. Why is it not working and is there something I could do?
EDIT: It works when this command: $('#children-div select[name="number_children"]').val('3').change();
or another way of triggering an event is typed in browser console, but not if the same code is executed from my chrome extension. Is it possible that Drupal somehow verifies what exactly triggered the event?
.trigger
like$('#children-div select[name="number_children"]').val('3').trigger('change');
t()
function MUST only take English strings. api.drupal.org/api/drupal/includes%21bootstrap.inc/function/t/…