-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
various format-with validators on one page. #30
Comments
You only need one format-of validator. What I do is to save the formtats in a "var params", with a lookup key representing the hash of the value, which is used in the input filed class (you'll see a number instead of the expression - because Regexp expressions are not valid XHTML classes). The format-of is generic and is smart enough to lookup the correct RegExp value depending on the class number (hashed value). If this don't work, its probably on of all the tiny bugs I'm not aware of. Does it not work? |
To generalize: Validatious-On-Rails tries to only generate one validator per validation type. Only the class attribute and some additional meta data for tricky stuff is different. |
Thank you for your very quick replies. Yes, it does not work in my case. I guess the problem is that v.to_js does not only contain the lines that look like v2.Validator.add(... but also the lines that look like v2.rails.params['888330768'] = ... In my case only the first two where generated, the third was omitted, although necessary: v2.rails.params['11024396765'] = /^[a-zA-z0-9_]*$/; v2.rails.params['789355800'] = ["admin","superuser","delete","blabla"]; v2.rails.params['888330768'] = /^[A-Z0-9_.%+-]+@(?:[A-Z0-9-]+.)+(?:[A-Z]{2,4}|museum|travel)$/i; |
OK, that's not good. Will need to look on that. Can't do it today for sure, but maybe tomorrow. I tried to avoid patch stuff while I got a huge refactor branch that should be merged in as soon as I get the AJAX controller test to pass, but this fix don't sound too messy. Actually I thought it worked already. =S |
Don't mind. There's no hurry. Thanks for looking into it. Let me know if I can provide additional info. |
I think this is the same bug that is happening to me. I've got the following validations:
If I remove one of them, everything works fine. But if I leave both of them, only the first one of them works on blur. The most annoying part is that in this situation when I click the submit button, validation errors for the "cif" field are shown by javascript, but the form is sent anyway. Here's the javascript code generated by the code above:
Thanks. |
Yea, a horrible bug. I hope I can get back to this project soon to fix these; working on a big project, so most my open-source is related to my needs for that project since a few months back. =( |
This seems to affect you whenever you have two or more regex validations on the same form. For me I was attempting to regex the number and expiry date of a credit card. The patch listed at the top of the issue fixed the problem for me but are there any side effects I should be aware of? (Thanks tec for the fix btw.) |
If I understand it correctly, the following line in lib/validatious-on-rails/model_validations.rb adds all the client-side and remote validations to one string and then to the html. The unless in the string inhibits identical validations to be added several times.
validator_js << v.to_js
unless existing_validators.present?
&& /#{v.name}/ =~ existing_validators
Unfortunately I had a case where several validations both had the v.name 'format-with', but with different formats. So one of them was not displayed. i solved it by also matching v.to_class in the unless. v.to_class differs because of the generated (random) params id.
validator_js << v.to_js
unless existing_validators.present?
&& /#{v.name}/ =~ existing_validators
&& /#{v.to_class}/ =~ existing_validators
The text was updated successfully, but these errors were encountered: