- ๐บ๐ธUnited States smustgrave
This doesnโt appear to be a bug related to this module. Would recommend trying a Drupal forum or stack overflow for assistance with your custom Ajax
In one of my view I am added exposed filter option in view exposed filter using better exposed filter module.
I have added country code field from address module in exposed filter & added one ajax call in it.
On this ajax call we want to update city in 2nd dropdown based on country select.
Below are my code for Ajax call implementation in .module file in hook_form_alter
if (isset($form['field_job_location_details_country_code'])) {
$form['field_job_location_details_country_code']['#ajax'] = [
'callback' => 'myAjaxCallback',
'disable-refocus' => true,
'event' => 'change',
'wrapper' => 'city-checkboxes',
'method' => 'replace',
'disable-refocus' => FALSE,
'progress' => array(
'type' => 'throbber',
'message' => t('Searching cities...'),
),
];
}
/**
* Ajax callback.
*/
function myAjaxCallback(array $form, FormStateInterface $form_state) {
//echo "Test are there.........";
$form_state->setRebuild(TRUE);
$localities = [1 => "Slough", 2 => "London", 3 => "Liverpool"];
$form['field_job_location_details_locality']['#options'] = [1 => "Slough", 2 => "London", 3 => "Liverpool"];
Checkboxes::processCheckboxes($form['field_job_location_details_locality'],$form_state,$form);
$response = new AjaxResponse();
$renderer = \Drupal::service('renderer');
foreach (Element::children($form['field_job_location_details_locality']) as $i) {
unset($form['my_field'][$i]);
}
\Drupal::formBuilder()->doBuildForm($form['#form_id'], $field, $form_state);
$response->addCommand(new ReplaceCommand("#my_field_id", $renderer->render($form['field_job_location_details_locality'])));
return $response;
}
This code is not working for me, ajax call is happened but this option is not chnaged.
Can anyone please let me know is there any solution to update checkboxes option on ajax callback using form_alter?
Closed: outdated
5.1
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
This doesnโt appear to be a bug related to this module. Would recommend trying a Drupal forum or stack overflow for assistance with your custom Ajax