tableau-mkt / jquery.addressfield

The simple, configurable, dynamic postal address form plugin.
https://tableau-mkt.github.io/jquery.addressfield
MIT License
66 stars 17 forks source link

Multiple addressfields and postal code validation #37

Open EAnushan opened 9 years ago

EAnushan commented 9 years ago

The plugin attaches a custom method name in the format 'isValid_' + field to each element on the form. This is particularly useful for postal codes, since the regexp validation for each is different per country.

When there are two postal code fields on the same page (in different forms), the second form's postal code validation seems to apply to the first as well. So if I select "Canada" in my second form, and leave the first form as "United Kingdom", the "United Kingdom" postal code will be validated using the "Canada" postal code rules. This is because we use the same method name for the validation rule, hence the conflict. They are both named "isValid_postalcode".

Should probably make this method name depend on the country, or a hash of the config array. Something along those lines.

iamEAP commented 9 years ago

That all makes sense. I'll have to think if the country/hash approach to naming the validation function is the best approach...

Thanks for the report!

EAnushan commented 9 years ago

I managed to solve it by modifying $.fn.addressfield.validate to use

methodName = 'isValid_' + field + $this.attr('name'),

Name may not be set on the element, I'll leave it up to you to decide how to best approach this.