I repost Jeff question below (Please see my response in next message):
Hi Chee Kin,
I tried posting a question to the discussion group but I don't see it
so I figured I'd ask you one more question.
I have a zipcode validator in my domain class like so:
zipcode nullable: true, maxSize: 20, matches: /\d{5}(-\d{4})?/
When I try entering a valid zipcode in my form, I always get a message
that the data is invalid, such as:
Property [zipcode] of class [class com.acme.Company] with value
[98765] does not match the required pattern [d{5}{-d{4})?]
Any idea why this isn't working?
Thanks,
Jeff
- Hide quoted text -
On Aug 10, 2011, at 2:40 AM, Chee Kin Lim wrote:
> Hi Jeff,
>
> You're welcome.
>
> Please add your custom logic to existing plugin's grails-validation-methods.js file instead of creating new one.
>
> Neither I know how to create unit tests for server-side validation, instead I create integration tests. Please see
http://code.google.com/p/jquery-validation-ui-plugin/source/browse/trunk/test/integration/org/grails/jquery/validation/ui/ConstraintsRetrieveTests.groovy for how tests call the hasError() at line 106.
>
> You are advice to post your future question to discussion group at
http://groups.google.com/group/jquery-validation-ui-plugin
>
> Best regards,
> Chee Kin
>
>
> On Tue, Aug 9, 2011 at 9:00 PM, Jeff Palmer <
jpa...@amientertainment.com> wrote:
>
> Hi Chee Kin,
>
> Thanks for getting back to me quickly. I still have 2 questions regarding how to use the plugin.
>
> * Where should the validation logic for the client-side validation go? I tried mimicking your plugin and creating my own grails-validation-methods.js file with my own custom logic, but that didn't seem to work.
> * The server-side validation doesn't seem to be working in my domain class unit tests. Have you found a way to test your validation logic in unit tests?
>
> Thanks for your help,
> Jeff
> From: "Chee Kin Lim" <
limch...@vobject.com>
> To: "Jeff Palmer" <
jpa...@amientertainment.com>
> Sent: Tuesday, August 9, 2011 3:27:07 AM
> Subject: Re: jQuery Validation UI Plugin
>
>
> Hi Jeff,
>
> Please look into Regular Expression stated in the PhoneUSConstraint (I copied it from some where), I not sure whether it is meeting your validation requirement.
>
> Hope this help.
>
> Best regards,
> Chee Kin
>
>
> On Tue, Aug 9, 2011 at 5:21 AM, Jeff Palmer <
jpa...@amientertainment.com> wrote:
>
> Hi Lim,
>
> I'm trying to use your jQuery Validation UI Plugin but am having a problem. I'm not really sure how to configure my domain objects to use custom constraints. For example, I noticed that you had created a PhoneUSConstraint. To use it, I added phone1 blank:false, maxSize: 20, phoneUS: true to my domain object. When I run my app and enter invalid data for the phone1 property, the form gets submitted. Am I doing something wrong? Also, when I modify my unit test for the domain, I'm doing something like:
>
> company = new Company(phone1: '555-555-55555')
> assertFalse company.validate()
> assertEquals 'phoneUS.invalid', company.errors['phone1']
>
> For some reason, however, the property is validating.
>
> Any idea what I'm doing wrong?