Validation on data-attributes with empty values

4 posts, 0 answers
  1. Chris
    Chris avatar
    2 posts
    Member since:
    Jul 2017

    Posted 11 Jul Link to this post

    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

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1966 posts

    Posted 13 Jul Link to this post

    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.
  3. Chris
    Chris avatar
    2 posts
    Member since:
    Jul 2017

    Posted 16 Jul in reply to Boyan Dimitrov Link to this post

    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

  4. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1966 posts

    Posted 18 Jul Link to this post

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