I have client-side validation installed the latest dev version 7.x-1.37+26-dev.

I assumed it was a good idea to enable it for all forms.

However whenever a form has built-in drupal AJAX requests and makes a request to the server for updated data Client-side Validation is unable to understand what is happening and prevents the AJAX request from happening.

For example this happens when using Commerce Shipping or Billing. It is possible to send a drupal AJAX request to retrieve existing shipping or billing addresses but Client-side Validation only sees empty fields and a change in the form state taking place and prevents the AJAX request from executing.

Another example is within the Admin configuration of rules when you want to switch from entering a field value to Data Selectors, Client-side Validation only sees an empty field and a change in the form state and prevents the AJAX request from executing.

There are other places where I have seen this problem and the solution every time is disabling Client-side Validation on the form which then allows the AJAX requests to be executed.

I do not think this is a problem restricted to one or two specific forms This seems to be a general problem with Client-side Validation and the execution of Drupal AJAX requests.

I do want Clientside Validation on the forms I have mentioned but I also definitely want AJAX as it makes the site much more user friendly. I cant figure how to enable Client-side Validation and have the drupal AJAX requests execute as and when needed.

Is this a bug or is there a configuration of Client-side Validation that allows drupal AJAX requests?

Comments

attiks’s picture

Assigned: Unassigned » Jelle_S

We added some extrra code to support AJAX, but apparently it isn't fully tested, see the following commits:
http://drupalcode.org/project/clientside_validation.git/commit/775b481
http://drupalcode.org/project/clientside_validation.git/commit/f71cada
http://drupalcode.org/project/clientside_validation.git/commit/4bf5b2d

If you could try debugging this, that would be awesome, I'll ask Jelle_S to have a look next week as well.

Jelle_S’s picture

If added a (partial) fix where submit buttons with '#limit_validation_errors' => array() won't trigger clientside validation. This fixes the Rules form you mentioned. I'm not sure how to fix the commerce forms yet.

nils.destoop’s picture

This problem still occurs on latest dev. I have a simple textfield that triggers an ajax request. The request is never happening untill the clientside validation passes.

whatdoesitwant’s picture

Priority: Normal » Major
attiks’s picture

Probably caused by http://drupalcode.org/project/clientside_validation.git/blobdiff/8ce6597... can you try removing the Drupal.behaviors.ZZZClientsideValidation and see if the problem still exists.

nils.destoop’s picture

Removing Drupal.behaviors.ZZZClientsideValidation fixes the problem for me.

attiks’s picture

@Jelle_S can you add an option to enable/disable this behavior?

Jelle_S’s picture

Status: Active » Fixed

The setting has been added and defaults to 'off', as it has been known to cause issues. It was added to support CTools Modal forms, which is more of an edge case than a general case. Because of that it seems like a good idea (to me) to disable it by default.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

dahousecat’s picture

I had the same problem and removing Drupal.behaviors.ZZZClientsideValidation from the js file worked for me too.

padma28’s picture

I have removed Drupal.behaviors.ZZZClientsideValidation from js file, worked for me. But, after serverside validation on the page, not getting form_id and my custom submit function is also not working.

padma28’s picture

I have tried one custom rule for a name field, FAPI + Clientside validation.
I've used the below code, but its not working.
Any help would be greatly appreciated, thanks!

// i have used the below code in hook_form_alter()
$form['account']['name']['#prefix'] = array('name_validate');

/**
 * Implements hook_fapi_validation_rules().
 */
function register_hehq_fapi_validation_rules() {   
  return array(
    'name_validate' => array(
     'callback' => 'register_hehq_validation_validate_name',
     'error_msg' => t('test value for %field')
    ),
  );
}

function register_hehq_validation_validate_name($value) {
  if (preg_match('/^[a-zA-Z0-9-]+$/', $value)) {
    return TRUE;
  }
  else {
    return FALSE;
  }
}

/**
 * Implements hook_clientside_validation_rule_alter()
 */
function register_hehq_clientside_validation_rule_alter(&$js_rules, $element, $context) {
  switch ($context['type']) {
    case 'fapi':
      if ($context['rule']['callback'] == 'name_validate') {
       $title = $element['#title'];
       $name = $element['#name'];
       drupal_add_js(drupal_get_path('theme', 'hehq') .'/script.js', 'file');
       $title = variable_get('clientside_validation_prefix', '') . $title .         variable_get('clientside_validation_suffix', '');
 $js_rules[$name]['messages']['notEmpty'] = t('Enter Valid name in !field.', array('!field' => $title));
      }
      break;
  }
}

//jQuery Wrapper
$(document).bind('onblur', function(event){
        jQuery.validator.addMethod("edit-field-user-name-und-0-value", function(value, element, param) {
          //return true if valid, false if invalid
          var regexp = /^[a-zA-Z0-9-]+$/
          return regexp.test(value.replace(' ', ''));
          //Enter a default error message.
        }, jQuery.format('Name is not valid'));
});
attiks’s picture

#12 Can you create a new issue for this please?

padma28’s picture

@attiks Thanks fixed #12 using the documentation at https://drupal.org/node/1324772

quiron’s picture

maybe this can be useful: https://www.drupal.org/node/2669646