Validation in custom editor template directive

2 posts, 0 answers
  1. zhivko.zhelezov
    zhivko.zhelezov avatar
    31 posts
    Member since:
    May 2011

    Posted 12 Jul Link to this post

    Hello,

    A question about validation in kendo UI datasource.

    I have a kendo grid and this grid has defined an editor template which is a custom directive 'tagSearch'. This custom directive has an input element into it with type text:

     editor: function (container, options) {
                                        var tagSelection = $('<div name="' + options.field + '"><tag-search></tag-search></div>');
                                        tagSelection.appendTo(container);
                                    }

     

    In validation method I have the following code (into dataSource):

     

      schema: {
                                model: {
                                    id: "itemId",
                                    fields: {
                                        tag: {
                                            type: "string",
                                            validation: {
                                                required: true,
                                                tagvalidation: function (input) {
                                                    if (input.is("[type=text]")) {
                                                       
                                                      if(...some validation...){

                                                         input.attr("data-tagvalidation-msg", "This tag is already added!");

                                                         return false;
                                                        }
                                                    return true;
                                                }
                                            }
                                        }
                                    }
                                }
                            }

     

    But the validation message with the text "This tag is already added!" does not appear. So what could be the possible reason(s) for this issue

     

    Thanks and Regards!

  2. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 13 Jul Link to this post

    Hello zhivko,

    If we assume that the validation rule code is executed, then most probably you need to use a message placeholder element as described here. Note that this placeholder is associated via the name of the input, thus you should make sure that this is correctly configured (you should be aware that name attribute is not valid for div elements). I suspect that you need such placeholder as by default the message will be displayed beside the validated input element. Which in your case may result depending on the tag structure in burying the element too deep in the custom element tree.

    Also you may know that the validation rules are executed for all input elements on the edit form, thus a more stronger check (for example by adding a specific attribute to the element and checking for it) inside the rule logic may be needed in order to prevent unwanted execution for other input elements.

     

    Regards,
    Rosen
    Telerik by Progress
     
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
     
  3. Kendo UI is VS 2017 Ready
Back to Top