Form.Validator problem caused by multiple validation on same element and no error message

154 views
Skip to first unread message

Mushr00m

unread,
Apr 29, 2013, 10:00:42 PM4/29/13
to mootool...@googlegroups.com
Hi !

I'm facing an issue with Form.Validator. In the doc http://www.mootools.net/docs/more125/more/Forms/Form.Validator they explain for example with "required" that an error message should show up (http://www.mootools.net/docs/more125/more/Forms/Form.Validator#Validators:required) but in my case nothing appear how should I do to get it ? Just to be clear I'm not using Form.Validator.Inline but just Form.Validator. All tuto on the internet use the Inline version, but I don't need all this.

My second issue, that is more important for me is that I use onElementValidate on my Form.Validator to do some addClass and removeClass. But if an input has more than one validator like "required validate-numeric" the onElementValidate will be called twice, and for an empty field, it will not pass the first time but will the second (for validate-numeric). So as I simply do if(passed){...}else{...} you can see the problem, as it's called twice and one time passes and not the other, it's doing something and undoing it...Is there a way to check if at least one validation failed ?

Thanks a lot for your help

Sanford Whiteman

unread,
Apr 30, 2013, 12:31:36 PM4/30/13
to Mushr00m
Can you put up a jsFiddle for this?

-- Sandy

Aaron Newton

unread,
Apr 30, 2013, 12:44:11 PM4/30/13
to mootools-users
Form.Validator is a base class that only validates forms. It does nothing else really; it provides no feedback to the user. Form.Validator.Inline is an implementation that displays feedback in a specific way that may or may not suit your design needs. If you look at that class's javascript you can see how there's not much in it. I have another implementation that creates tooltips (see dev.clientcide.com), for example.

onElementValidate is an event fired whenever an element is validated with a validator. Form.Validator also fires onElementPass and onElementFail whenever an input passes or fails it's set of validators (which is probably what you want).

Further, you get a callback when the form as a whole is evaluated. Inputs that pass are given the class 'validation-passed' and those that fail are given the class 'validation-failed'.

Somewhere in there should be a solution that you can work with.




--
 
---
You received this message because you are subscribed to the Google Groups "MooTools Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mootools-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Mushr00m

unread,
Apr 30, 2013, 12:45:24 PM4/30/13
to mootool...@googlegroups.com
Thanks for your time !

I made it here : http://jsfiddle.net/znmf4/5/

As you can see the first field is only required, so when submitting and empty form it's in red as its label. But the second only the input is red not the label. This is because the onElementValidate is called twice, the first time it failed because the input is empty, but the second time it passes because the input is validate numeric (empty is ok for validate-numeric). And that's me issue, I need to change the part on the onElementValidate to make sure ALL the validation passed...

Mushr00m

unread,
May 1, 2013, 3:37:02 PM5/1/13
to mootool...@googlegroups.com
Perfect Nutron ! I needed onElementPass and onElementFail..
Thanks a lot.
Reply all
Reply to author
Forward
0 new messages