Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery remote validation with server generated error message

Tags:

jquery

I am using the Validation jQuery plugin to do some validation. I have a service which returns "true" and "false" right now and everything is great.

However, the error message I am using is "That name is already taken."

I want the error message to be "That name is already <a href="/item?id=543"> taken</a>." where that item id is something returned from the server. But I can't figure out how to return anything from the server other than a single true or false and still have the validation work.

I know I can do "The name xxx is taken" using JQuery.Format("The name {0} is taken") but I really want to give a hyperlink to the existing item, and I don't want to have to change the item pages to accept a name instead of an id.

like image 214
tster Avatar asked Aug 26 '10 20:08

tster


1 Answers

The validation plugin handles this already, but the call type is "json", so you need to make sure the string (error message) is passed in quotes, like this:

"Error Message"

The plugin will use this as the displayed error message, handy eh? :)

like image 67
Nick Craver Avatar answered Sep 24 '22 02:09

Nick Craver