I have a select form element that fires an ajax callback function everytime its value changes.
$form['template_options'] = array(
'#type' => 'select',
'#options' => array(
1 => t("Student"),
2 => t("Employee"),
),
'#default_value' => 1,
'#title' => t('Select'),
'#ajax' => array(
'callback' => 'myid_select_template',
'wrapper' => 'myid_dynamic_input_information',
),
'#suffix' => '<div id="myid_dynamic_input_information"></div>',
);
The function myid_select_template
is a callback function triggered when the select form element changes it's value.
function myid_select_template($form, &$form_state){
$form = array();
$form['form']['birthdate'] = array(
'#title' => t('Date of Birth'),
'#type' => 'date_popup',
'#timepicker' => 'timepicker',
'#date_format' => 'd/m/Y',
'#date_year_range' => '-100:+0',
'#default_value' => date("Y-m-d H:i:s", time()),
);
return $form;
}
I already enabled Date API, Date Pop-up and Date Picker module. I notice that the date_popup form element doesn't show when I place it in a form not rendered in ajax callback function.
The HTML below is an output of an ajax callback function:
<div class="container-inline-date">
<div class="form-item form-type-date-popup">
<label>Date of Birth </label>
<div id="" class="date-padding clearfix"></div>
</div>
</div>
The HTML output below is the output of a working Date Picker not rendered by ajax function:
<div class="container-inline-date">
<div class="form-item form-type-date-popup form-item-birthdate">
<div id="edit-birthdate" class="date-padding">
<div class="form-item form-type-textfield form-item-birthdate-date">
<label for="edit-birthdate-datepicker-popup-0">Date </label>
<input type="text" id="edit-birthdate-datepicker-popup-0" name="birthdate[date]" value="27/07/2015" size="20" maxlength="30" class="form-text">
<div class="description"> E.g., 27/07/2015</div>
</div>
</div>
</div>
</div>
I notice it is rendered incompletely. Why?
myid_select_template($form, &$form_state)
.Also, see the example given in Ajax framework. – kiamlaluno♦ Jul 27 '15 at 5:29