Using custom constraints

24 views
Skip to first unread message

Thomas Buckley

unread,
Feb 11, 2013, 5:22:21 AM2/11/13
to jquery-valida...@googlegroups.com
Hi

I nealy have my form valadting client side based on my command object constrainst.
There is one problem, I have a custom constraint in my command object:

startTime(nullable: false, validator: {startTime, deal ->
if ((!DateUtils.isSameDay(startTime, new Date()) && startTime.before(new Date()))) //Start date is today or future but not before end date
{
return "pastDate"
}
if (deal.endTime && startTime.after(deal.endTime)) {
return "before.endTime"
}
})

This results in the following rendered jQuery validation code generation in my page:

startTime: {
date: true,
required: true,
validator: {
url: '/appContextRoot/JQueryRemoteValidator/validate',
type: 'post',
data: {
validatableClass: 'myapp.command.tester.testerDealCommand',
property: 'startTime'
}
}
}

Obviously, the custum constrains logic withing "validator:" does not work.

What is the best approach to get this custom validator working? 
1: Some form of Ajax call?
2: Use Custom Constraits plugin and add js code to grails-validation-methods.js?
3: Some other way?

I'm unsure of using option 2....is there some way to extend your plugin? 
I do not want to have to commit and maintain an seperate version of your plugin to our source code repository.

Thanks
Reply all
Reply to author
Forward
0 new messages