Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #15 broke the display of field values in validation error messages. #24

Closed
jonroler opened this issue Mar 25, 2013 · 2 comments

Comments

@jonroler
Copy link
Contributor

The fix for issue #15 added the encodeAsJavaScript() call at the end of JqueryValidationService.getMessage() in order to allow single quotes inside of message strings. This method escapes single quotes in the message which is exactly what is needed to allow arbitrary strings to be placed inside of a javascript string. However, this type of escaping can't be performed on actual javascript code, which is what is happening as a result of issue #15:

validation-javascript

We are passing actual javascript (' + $('#name').val() + ') to get the value of the field included in the message string. However, when the single quotes are escaped, they just appear inline in the code.

The best fix I can think for this is:

  1. First pass a placeholder string (like "JAVASCRIPT_TO_RETRIEVE_VALUE_GOES_HERE") as an argument to messageSource.getMessage()
  2. Call encodeAsJavascript() on the result (the placeholder will still be present here).
  3. Finally, replace the placeholder with the actual javascript.

This solution allows the message to be escaped for quotes as needed, and the javascript can then be added in the correct place without the escaping. The main downside to this approach is some arbitrary placeholder text has to be chosen that hopefully won't appear elsewhere in the message. I don't see any way around this, however, so we'll just have to pick something very likely to not appear in any actual message.

@jonroler
Copy link
Contributor Author

Proposed fix is included in #25. With the fix, values now display correctly in javascript messages (instead of displaying the javascript code itself). This bug is actually pretty bad since many of the default grails error messages include the value, so people (like me) who just decide to try out this plugin with a new project will immediately encounter this bug.

limcheekin added a commit that referenced this issue Mar 26, 2013
Fix for issue #24: allow values to appear in client-side validation error messages
@limcheekin
Copy link
Owner

Good catch! Thanks for report the issue with fix provided. This fix was just released in 1.4.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants