webform and jquery
Hello to the forum. Hi Chris!!
Recently a made a module which provide ajax functionality to a webform (webform module). Nothing complicated, just something to get the work done. In my webform i have a textfield and via the hook_form_alter() i added to it a calendar by using the jquery ui which is in the core of the drupal 7 now. The problem is when i submit the form using ajax.
Let's say i leave the textfield with the jquery ui calendar blank. so the submition returns the validation error and the form as it normally should do without ajax. Now when i click the textfield the calendar doen't pop up. I guess this is happening because the new form need to rebind this action.
How i should do it in Drupal ? Here is my code in the hook_form_alter()
switch ($form_id) {
case 'webform_client_form_11' :
$form['submitted']['ev_date']['#attached']['library'][] = array('system', 'ui.datepicker');
$form['submitted']['ev_date']['#attached']['js'][] = array('data' => 'jQuery(document).ready(function(){jQuery("#edit-submitted-ev-date").datepicker();});', 'type' => 'inline');
// add the ajax properties to the submit button
$form['actions']['submit']['#ajax'] = array(
'callback' => 'aw_ajax_callback',
'wrapper' => 'webform-client-form-11',
'method' => 'replace',
'effect' => 'fade',
);
break;
}
}
ev_date is the textfield i add the calendar.