0
votes

Here is my situation:

I have a very long multi-page survey built by webforms in drupal. The questions are not required but we don't want the users to skip all the questions too easy by just clicking Next Page button.

So this is what we need:

When the user try to click on "Next Page" button with any empty fields on the page, error or warning messages will show up, "Are you sure you want to skip this question?", as well as a skip button next to it. When the user click on the skip button, the message disappears and they click on the next page button to proceed the survey.

Here are my thoughts on this:

I used webform validation module to create an Not Empty validation and apply it to the fields.

in webform_validation_validators.inc:

case 'skip_if_empty':

foreach ($items as $key => $val) {
    if (count($val) == 0) {
        drupal_set_message(t('This field is empty.'), 'warning');
        // do something, not sure about it here
    }
}

Another thought:

I used the Dismiss module to display an X button next to the error message. Can I add some functions to the X button to bypass the validation when it is clicked?

And here is the script for the Dismiss module, :

(function ($) {    
    Drupal.behaviors.dismiss = {
        attach: function (context) { 
            $('.messages').each(function () {  
                var flag = $(this).children().hasClass('dismiss');
                if (!flag) {
                    $(this).prepend('' + Drupal.t('Close this message.') + '');
                }  
            });
            $('.dismiss').click(function () {
                $(this).parent().hide('fast');
                // some functions to bypass validation to the field?
            });
        }
    }   
})(jQuery);

I don't know what to do to after the //. Or is there any other ideas that will work?

1

1 Answers

0
votes

AS per the you requirement mention

Take this example

You have created webform having field like

Firstname with required field Lastname with required field

Then Next button button

When user click next button then error show because you have make the fields are required

When your showing "Dismiss button" next to each field.

Whenr user click "Dismiss button" that time you have to remove "required" attribute of field using jquery or drupal ajax

After that when user click next button then user not get any kind of required field validation error.