This is a migrated thread and some comments may be shown as answers.

Format Error Message for Custom Validator

2 Answers 199 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 26 Mar 2014, 03:41 PM
I have implemented custom rules for the Kendo Validator.  I would like to be able to use a format string for my error message and replace parameters in it with values from the validation.  For example, on the server side I am using a format string of: "{0} cannot contain two groups with the name '{1}'." and I replace {0} with a friendly name of the input and {1} with the duplicated group name (a value available as a result of the validation logic).  If I use this same string as the error message for the Kendo validation rule, the {0} is being replaced automatically by the value of the "name" attribute on the input being validated, and the {1} is being removed.

Is there a standard way for me to provide my own values to format the validation error message?

Thanks,
Brian

2 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Valchev
Telerik team
answered on 27 Mar 2014, 03:44 PM
Hello Brian,

Validator warning messages does not accept kendo templates which is why you are not able to apply a format. As an alternative solution I suggest you to define the message which you would like to format as a JavaScript function (please check the code example from here). This will allow you to construct the warning message and use kendo.toString to format the values according to your requirements.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Brian
Top achievements
Rank 1
answered on 27 Mar 2014, 03:52 PM
Alexander,
Thank you for your reply.  I am doing as you suggested and using a method to return the message. 

If anyone else is looking to do this:
I added an attribute to the input that is being validated to provide the friendly name, and in the validator logic I add an attribute to the input and set it to the duplicate group name.  Then in the method for the error message I replace my placeholders in the error message with the values read from the attributes.

Brian
Tags
Validation
Asked by
Brian
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Brian
Top achievements
Rank 1
Share this question
or