webform and jquery

No replies
dianikol
Offline
Last seen: 7 years 38 weeks ago
Joined: 2011-04-27

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()

function module_form_alter(&$form, &$form_state, $form_id) {
    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.

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:


Loading...
Contact us

Below are the supported keyboard shortcuts for our video player.

space
Start / stop video
shift
Go to next video
shift
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
1...9
Jump to a percentage (2 is 20%, for example)
f
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
$29
1 month
$156
6 months
10% off
$276
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
user
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.