Custom client-side validation

29 views
Skip to first unread message

Jeff

unread,
Aug 10, 2011, 10:08:41 AM8/10/11
to JQuery Validation UI Plugin
Hi,

I've read the documentation but still have a question regarding how to
use the jQuery Validation UI plugin.

Where should the validation logic for custom client-side validation
go? I tried mimicking the plugin and creating my own grails-validation-
methods.js file with my own custom logic, but that didn't seem to
work. I don't see any override scripts available either.

Thanks.

limcheekin

unread,
Aug 10, 2011, 7:25:30 PM8/10/11
to JQuery Validation UI Plugin
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?

Chee Kin Lim

unread,
Aug 10, 2011, 8:12:36 PM8/10/11
to JQuery Validation UI Plugin
Hi Jeff,

Try to enclose the regular expression with " instead of /.

Please refer http://grails.org/doc/latest/ref/Constraints/matches.html to find out more.


Hope this help.

Best regards,
Chee Kin

Jeff

unread,
Aug 17, 2011, 10:43:11 AM8/17/11
to JQuery Validation UI Plugin
I tried enclosing the regular expression in quotes but the problem
still persists. I was able to get it to work by using the following:

matches: /[0-9]{5}(-[0-9]{4})?/

Anyone know why I can't use \d instead of [0-9]?
> >http://code.google.com/p/jquery-validation-ui-plugin/source/browse/tr...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 <
> > jpal...@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" <limchee...@vobject.com>
> > >     To: "Jeff Palmer" <jpal...@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 <

Chee Kin Lim

unread,
Aug 17, 2011, 7:20:12 PM8/17/11
to jquery-valida...@googlegroups.com
Hi Jeff,

It may cause by back slash "\", try to escape it by slash "/".

Best regards,
Chee Kin
Reply all
Reply to author
Forward
0 new messages