javascript - How do I get KendoUI Validator to ignore hidden form elements? -


i attempting use kendoui validator asp.net webforms project. have simple page, has number of inputs, , of course asp.net adds hidden form elements well.

i have following questions:

  1. why kendoui validator not ignore hidden form fields, , how to?
  2. why kendoui apply rules every input field, , how ignore fields. want declarative way this, not adding sorts of exceptions in validation rule, per example in kendoui validator api page.
  3. shouldn't if no rule set attribute in input element (eg; required) no validation applied?

behavior getting:

  • with no validation specific attributes on input element @ all, validation rules still applied when call .validate()
  • hidden form elements validated.

i using following kendo:

http://cdn.kendostatic.com/2013.2.716/js/jquery.min.js http://cdn.kendostatic.com/2013.2.716/js/kendo.all.min.js http://cdn.kendostatic.com/2013.2.716/styles/kendo.common.min.css http://cdn.kendostatic.com/2013.2.716/styles/kendo.default.min.css 

i have put fiddle demonstrates this: http://jsfiddle.net/codeowl/b5ml4/3/

and here code, don't have access fiddle:

i have following markup:

<form action="/" id="testform">     <input type="hidden" name="__eventtarget" id="__eventtarget" value="" />     <input type="hidden" name="__eventargument" id="__eventargument" value="" />      <input type="text" id="testinput" value="">     <a id="testvalidate" href="javascript:;">validate</a> </form> 

and following script:

var validatable = $("#testform").kendovalidator({     rules: {         testrule1: function (input) {             // "tom" valid value firstname input             return input.is("[name=firstname]") && input.val() === "tom";         },         testrule2: function (input) {             return $.trim(input.val()) !== "";         }     },     messages: {         testrule1: "your name must test",         testrule2: "your name must foo"     } }).data("kendovalidator");  $("#testvalidate").click(function () {     if (validatable.validate()) {         alert('passed');     } }); 

and when press validate link shows validation messages hidden fields.

for interested, did response question. had post on kendoui premium forums respond.

here response: how kendoui validator ignore hidden form elements?

indeed, hidden input elements passed through validation rules logic default due fact there multiple widgets has hidden input part of there markup. however, built-in rules relays on presence of attributes, if there missing no validation happen on hidden inputs. therefore, own custom rules should handle scenario , skip appropriate elements. example:

testrule2: function (input) {     if (!input.is(":hidden")) {         return $.trim(input.val()) !== "";     }     return true; } 

Comments

Popular posts from this blog

ruby on rails - Permission denied @ sys_fail2 - (D:/RoR/projects/grp/public/uploads/ -

javascript - Laravel datatable invalid JSON response -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -