message.properties label not being used in Javascript

178 views
Skip to first unread message

John Moore

unread,
Jun 14, 2011, 7:16:51 AM6/14/11
to JQuery Validation UI Plugin
Just started playing with the plugin and it looks pretty neat. I
spotted a slight problem, though. In message.properties, you can
specify a human-friendly label for properties. For example, in my
little test app I have:

thing.height.label=Height

This shows fine in the error messages returned from the server, but it
doesn't seem to work for the JavaScript on the client. In my
constraints for Thing, I have 'height min:20,max:40, nullable:false'.
This is what we get in the JavaScript - note the lowercase form of the
property, not using the label:

messages: {
height: {
digits: 'Property height must be a valid number',
min: function() { return ''height' with value ' + $('#height').val()
+ ' is less than minimum value 20'; },
max: function() { return ''height' with value ' + $('#height').val()
+ ' exceeds maximum value 40'; },
required: ''height' cannot be empty'
},

Also, I get this JavaScript error, which I presume is related:


Error: missing ; before statement
Source File: http://localhost:8080/MiniDemo/thing
Line: 56, Column: 26
Source Code:
min: function() { return ''height' with value ' + $('#height').val()
+ ' is less than minimum value 20'; },

Chee Kin Lim

unread,
Jun 14, 2011, 9:42:37 PM6/14/11
to jquery-valida...@googlegroups.com
Hi there,

Thanks for trying the plugin.

The problem is come from the statement below:
''height' with value '

Did you see nested single quote (')? Try to remove the single quote specified in your messages.properties.

Hope this help.

Best regards,
Chee Kin

John Moore

unread,
Jun 15, 2011, 4:22:27 AM6/15/11
to JQuery Validation UI Plugin
Thanks, that stops the Javascript error. But it doesn't address the
first issue. I've been looking at the code and trying to work out why
'renderValidationScript' does not use the label in its messages, where
server-side messages do. The best thing I could come up with was an
after-the-event replacement of the 'raw' property name with the
correct labelled form in the message, but this is clumsy. There must
be a better way.

Chee Kin Lim

unread,
Jun 15, 2011, 5:27:49 AM6/15/11
to jquery-valida...@googlegroups.com
Hi John,

Is the person sample app working? Had you tried it?

Best regards,
Chee Kin

John Moore

unread,
Jun 15, 2011, 5:59:15 AM6/15/11
to JQuery Validation UI Plugin
Sure, the Person sample app works fine. But it doesn't illustrate what
I was meaning. With normal server-side validation, you can have
something like the following in your messages.properties:

person.phone.label=Phone Number

Then the server-side validation error messages will automatically
contain this human-friendly form, so you'd automatically get something
like the following, without having to specify for each message type:

Phone Number cannot be blank

Your client-side validation messages do not use this, and I'm trying
to work out how to get them to do so.

Chee Kin Lim

unread,
Jun 15, 2011, 6:06:49 AM6/15/11
to jquery-valida...@googlegroups.com
Hi John,

Thanks for quick response.

Now only I understood the issue you faced. It is more to enhancement instead of issue in my opinion.

Anyway, please share your approach here if you found a way to make it works.

Thanks,
Chee Kin

John Moore

unread,
Jun 15, 2011, 6:10:47 AM6/15/11
to JQuery Validation UI Plugin
Sure, it's an enhancement rather than an issue with the existing
plugin (for which I am grateful). I think I'll have to dig into the
Grails source to see how the label is used there. I'll let you know if
I find anything useful.
Reply all
Reply to author
Forward
0 new messages