Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By dpolant on
Below is the form fragment that I am having trouble with:
// search filters
$form['search_widget']['filters'] = array(
'#theme' => 'qapi_search_filters_display',
'#tree' => true,
);
// filter storage element
$form['search_widget']['filters']['filter_json'] = array(
'#type' => 'hidden',
'#default_value' => drupal_json_encode($saved_filters),
'#attributes' => array(
'id' => 'filter-json'
),
);
if (isset($form_state['storage']['filters'])){
foreach ($form_state['storage']['filters'] as $n => $filter){
$form['search_widget']['filters']['rows'][$n] = array(
'#type' => 'checkbox',
'#attributes' => array(
'class' => array('qapi-search-widget-filter-cb'),
'id' => 'filter-' . $n,
),
'#filter' => $filter,
'#default_value' => 1,
'#ajax' => array(
'callback' => 'qapi_search_filters_cb_handler',
'event' => 'change',
'progress' => array(
'type' => ''
)
)
);
}
}
In my theme_qapi_search_filters_display, I am running drupal_render on the $form['search_widget']['filters']['rows'][$n] elements, but they are not getting processed with the #ajax behaviors that I need.
Any ideas?
Comments
Resolved: id attribute was the problem
It actually had nothing to do with using drupal_render(), but rather the
'id' => 'filter-' . $n,
line was causing ajax.js not to be able to target this element for the addition of the "ajax-processed" class.- Dan
Have same problem. drupal
Have same problem. drupal_render inside theme function doesn't add 'ajax-processed' to an element class - it has only 'form-submit'.
Played with ID - didn't help. Why do you think the problem was with?
'id' => 'filter-' . $n,
How did you fix it?
Thanks!
This thread is two years old,
This thread is two years old, you're not likely to get an answer.