Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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
Comment #1
attiks CreditAttribution: attiks commentedValidation should be ignored if the button has a class 'cancel', what module are you using? Commerce?
Comment #2
D34dMan CreditAttribution: D34dMan commented@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 :/ )
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.
Comment #3
attiks CreditAttribution: attiks commentedwe'll see how we can implement this, we'll add this as a global and as a per form setting.
Comment #4
Jelle_SThe 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.
Comment #5
Jelle_SPull request created.
Comment #6
jitse CreditAttribution: jitse commentedFor future readers: jquery.validate changed to "formnovalidate".
See this comment on githun.
Comment #7
Agence Web CoherActio CreditAttribution: Agence Web CoherActio commentedIn 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)
Laurent
Agence Web Coheractio