Problem with validating number type filed

2 posts, 0 answers
  1. Mate
    Mate avatar
    13 posts
    Member since:
    Sep 2013

    Posted 07 Jan 2015 Link to this post

    Hi,

    I am having issues with number type field validation.
    The fields have a default value of 0, and they are required, but Kendo still shows an error message when the field is not empty.

    This is my number field:
    <input type="number" id="someid" name="somename" value="0" min="0" max="100" required="required" validationMessage="This is a required field">


    This is my js:
    $(document).ready(function(){
     
               $("form").kendoValidator({
                  rules: {
                    radio: function(input){
                      if (input.filter("[type=radio]") && input.attr("required")) {       
                            return $(".edit_filling").find("[data-qs=" + input.attr("data-qs") + "]").is(":checked");
                      }
                      return true;
                    }
                  },
                  messages: {
                    radio: "This field is required"
                  }
                });
     
           });

    Ideally this should be valid even if the user doesn't touch it. Of course if he deletes the 0, or inputs a higher value than 100 then the error message should be displayed.

    Please help me with this issue.

    Best Wishes,
    Matt
  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2877 posts

    Posted 09 Jan 2015 Link to this post

    Hello Mate,

    The problem is in the custom validation rule:

    radio: function(input){
      if (input.filter("[type=radio]") && input.attr("required")) {      
            return $(".edit_filling").find("[data-qs=" + input.attr("data-qs") + "]").is(":checked");
      }
      return true;
    }

    Code in red will return empty array when evaluated against the input type="number" element. Code in green will return true. The "if" condition will be true, because [ ] is not false.

    Please try the following:

    if (input.filter("[type=radio]").length && input.attr("required")) {


    Regards,
    Alexander Valchev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
Back to Top