If client validation is turned on for say a checkout form, and the user wishes to cancel filling up of form, client validation throws an error pointing to required fields.

I think there should be some provision to add some html selector for input types that should be ignored by clientside validation module.

Thank you.

Comments

Validation should be ignored if the button has a class 'cancel', what module are you using? Commerce?

Title:Make Client side validation not respond to certain input elements like Cancel button.Make Client side validation not respond to certain input elements like Cancel button with classes other than "cancel".

@attiks, Yes as you have assumed i am using Commerce.

Now following is the code for default commerce checkout cancel button (Just FYI: the id could be suffixed with --1, --2, --3 ... depending on how many times the form have been submitted and returned back from server, that's the case when Clientside validation is not used :/ )

<input class="checkout-cancel form-submit" type="submit" id="edit-cancel" name="op" value="Cancel">

While using Clientside Validation (nice module btw) i found that i don't have to implement hook_form_alter or anything of that sort. It just works. That is a good thing.

Now as you can see commerce checkout form is injecting checkout-cancel class. so it is trying to validate the form when its clicked.

Now if i had a provision to enter a custom class ( hence this feature request ) telling Clientside Validation to ignore those input buttons, i would put "checkout-cancel" in there.

I know i could bump this issue in commerce queue and request them to add "cancel" class to those button to make Clientside Validation work out of the box for those forms. But then we would have to do this for every other modules who implement custom classes in their buttons.

I am interested in submitting a patch if you give me can guide me.

Assigned:Unassigned» Jelle_S

we'll see how we can implement this, we'll add this as a global and as a per form setting.

Status:Active» Postponed

The problem is that the cancel class is hardcoded in jquery.validate.js, so we can't provide it as a setting. I opened an issue in their issue queue. Postponed until that feature is added.

For future readers: jquery.validate changed to "formnovalidate".
See this comment on githun.

Issue summary:View changes

In case you need to bypass clientside validation for commerce checkout back button, you can use a hook_form_alter as below (replace MODULENAME by the name of your module)

function MODULENAME_form_alter(&$form, &$form_state, $form_id){
  // Add a "cancel" class to back button in order to bypass clientside validation
  if (strpos($form_id, 'commerce_checkout_') !== FALSE){
    if (isset($form['buttons']['back'])){
      $form['buttons']['back']['#attributes']['class'][] = 'cancel';
    }
  }
}

Laurent
Agence Web Coheractio