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

Why is custom validation for a field run on every field?

3 Answers 500 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 13 Jun 2014, 02:57 PM
This doesn't make any sense to me. I don't see it pointed out anywhere in the docs either.

You can see in the custom validator example:

productnamevalidation: function (input) {
  if (input.is("[name='ProductName']") && input.val() != "") {}

I didn't pay any attention to the .is()​ at first, but now I know why. I thought updating to the latest KendoUI would resolve the issue, but it does not. You can still see the behavior on the trykendo site: http://trykendoui.telerik.com/ajat/2. Open the console and you can see that it runs for every field.

Please incorporate the .is() check or another approach so that I don't have to remember to do it...

3 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 16 Jun 2014, 08:36 AM
Hello Ryan,

Updating the Kendo UI will not change the functionality that you are referring to. In general the validation rules are run for every component and there is no way to say this rule should be run for this component, actually it is pretty much the same as you can check in  the rule whether the component that you are looking for is being validated. This gives you better flexibility as you can use one and the same rule for multiple inputs.

If you want you can create separate validators for each and every input in your form, however you will need to manually call the validate() method for every one of them. 

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Ryan
Top achievements
Rank 1
answered on 16 Jun 2014, 11:33 AM
Flexibility? I'm OK with a validator being run against every column if the definition of such validator is defined in a way that is intuitive. That is not the case for custom field validation in the grid. Take the following definition:

01.$("#grid").kendoGrid({
02.    dataSource: new kendo.data.DataSource({
03.        schema: {
04.            model: {
05.                id: "ProductID",
06.                fields: {
07.                    ProductID: { editable: false, nullable: true },
08.                    ProductName: {
09.                        validation: {
10.                            required: true,
11.                            productNameValidation: function (input) {
12.                                console.log('Im going to run everywhere!');
13.                            }
14.                        }
15.                    },
16.                    UnitPrice: {
17.                        validation: {
18.                            required: false,
19.                            unitPriceValidation: function (input) {
20.                                console.log('Im going to run everywhere!');
21.                            }
22.                        }
23.                    }
24.                }
25.            }
26.        }
27.    }),
28.    // ...
29.});

For ProductName, I expect the required property to only affect ProductName and not the other fields. Just the same, productNameValidation should not be run against other fields. If model had a generic validation​ property, I would understand and call this flexible.

The API docs do not make mention of this custom-validation-will-be-run-everywhere behavior with regards to the grid. If you look at KendoUI Validator's rules configuration this behavior makes sense. The selector, the entire form, has a generic custom validator that is intended to be run against every input. In the case of the grid and defining my validator for a field I would expect the selector to be constrained to that field and not the entire grid. Again, if model were defining the validator it would make sense but its the individual field.

The entire kendoUI library is designed methodically and intuitively -- except for this. I cannot believe that this is the intended behavior but rather a shortcoming in the way that the validator is applied to a model/grid.
0
Kiril Nikolov
Telerik team
answered on 17 Jun 2014, 11:24 AM
Hello Ryan,

The validation is run against the container. What this means is that if you have inline editing the whole line is the container, so the validator runs against all the elements in this container, if you have incell editing the only the cell being edited will be validated as it is the only container in the form.

As for your remarks about the documentation regarding the validator - I agree with you that it needs improvement and I would like to assure you that we are constantly striving to improve the quality of the documentation.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Ryan
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Ryan
Top achievements
Rank 1
Share this question
or