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

Validation in custom editor template directive

1 Answer 208 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
zhivko.zhelezov
Top achievements
Rank 1
zhivko.zhelezov asked on 12 Jul 2016, 08:33 AM

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!

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 13 Jul 2016, 07:03 AM

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.
 
Tags
Data Source
Asked by
zhivko.zhelezov
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or