I have a select field in my custom module (Drupal 7), which needs to refresh the values of 2 different field types when a value is selected, firstly a checkbox field, which currently is refreshed correctly when am changing the dropdown value, and a text field, which is not changing, as it keeps the value from the first dropdown option by default.
Samples of my codes:
$form['webform_name'] = array(
'#type' => 'select',
...
#ajax' => array(
'event' => 'change',
'callback' => 'ajax_checkbox_callback',
'method' => 'replace',
'wrapper' => array('checkboxField','txtField'),
)
$form['checkboxField'] = array(
'#type' => 'checkboxes',
...
'#prefix' => '<div id="checkboxField">',
'#suffix' => '</div>',
$form['txtField']=array(
'#type' => 'textfield',
...
'#prefix' => '<div id="txtField">',
'#suffix' => '</div>',
function ajax_checkbox_callback($form, &$form_state) {
return array(
'#type' => 'ajax',
'#commands' => array(
ajax_command_replace("#checkboxField", render($form['checkboxField'])),
ajax_command_replace("#txtField", render($form['txtField']))
)
);
}
How can I make the txtField
field to clear and load the corresponding value every time I change my drop-down values?