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

Problem with validating number type filed

1 Answer 28 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Mate
Top achievements
Rank 2
Mate asked on 07 Jan 2015, 03:23 PM
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

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 09 Jan 2015, 09:01 AM
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!
 
Tags
Validation
Asked by
Mate
Top achievements
Rank 2
Answers by
Alexander Valchev
Telerik team
Share this question
or