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

Validation on data-attributes with empty values

3 Answers 1669 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 12 Jul 2017, 02:42 AM

Hi,

We're having some problems with Kendo MVC Validation when data attributes on inputs have no value.

For example (when using FluentValidation integrated with MVC) our inputs are generated as follows:

<input class="form-control text-box single-line k-invalid valid" data-val="true" data-val-number="The field Range1 must be a number." data-val-range="'Range1' must be greater than or equal to ''." data-val-range-max="" data-val-range-min="" data-val-required="'Range1' should not be empty." id="Range1" name="Range1" type="number" value="" aria-required="true" aria-describedby="Range1-error" aria-invalid="true">

 

The problematic code being: data-val-range="'Range1' must be greater than or equal to ''." data-val-range-max="" data-val-range-min=""

When using the input the error appears no matter what value you enter: Range1' must be greater than or equal to ''.

The reason these attributes are generated without values is because they are dynamic/not constant. The FluentValidation rule is that the Range field must be greater than another field on the screen.

I know that I could write custom validation for this rule but actually I am happy for the input to ignore the validation of the range in this case.

The same application works fine when using jQuery validate (jQuery validate ignores the empty range attributes and the form can be submitted).

How do I stop Kendo Validator attempting to validate this attribute? Shouldn't it ignore the attributes as they are empty (not valid), and treat the input as valid?

(image attached shows the problem)

Regards,

Chris

3 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 13 Jul 2017, 01:07 PM

Hello Chris,

I guess that the provided output is generated following the Validation tutorial. In both cases (custom attribute validation) it is specified what is the base value or the field model for the custom validation. Could you please share the code or the scenario that requires the custom validation? 

Regards,
Boyan Dimitrov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Chris
Top achievements
Rank 1
answered on 16 Jul 2017, 08:56 PM

Hi Boyan,

No, this wasn't a result of following the Validation tutorial. As mentioned in the OP we are using FluentValidation nuget package to write our custom validation. In this example we have a rule for the field. 

RuleFor(x => x.MaximumDate).GreaterThanOrEqualTo(x => x.DateOfBirth); // FluentValidation rule

This triggers MVC to add html data attributes to the input:

data-val-range-min=""

data-val-range-max=""

When we use jQuery validate on the project these attributes are ignored however when we add Kendo Validation to the project the values above are being used to validate the input and because of their lack of values the validation always fails.

I would like Kendo Validation to ignore these attributes in the same manner that jQuery validation does and am wondering why Kendo Validation attempts (and fails) to validate the input when the data attributes are not set in this way?

Regards,

Chris

0
Boyan Dimitrov
Telerik team
answered on 18 Jul 2017, 01:49 PM

Hello Chris,

I am afraid that there is no configuration option for ignoring the empty data attribute values. The only solution for such cases would be using custom rules. 

Regards,
Boyan Dimitrov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Validation
Asked by
Chris
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Chris
Top achievements
Rank 1
Share this question
or