Format Error Message for Custom Validator

3 posts, 1 answers
  1. Brian
    Brian avatar
    58 posts
    Member since:
    Jul 2011

    Posted 26 Mar 2014 Link to this post

    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. Answer
    Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 27 Mar 2014 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Brian
    Brian avatar
    58 posts
    Member since:
    Jul 2011

    Posted 27 Mar 2014 in reply to Alexander Valchev Link to this post

    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
Back to Top