mercredi 4 février 2015

Check kendo validations before submit mvc4

maybe my problem has a simple answer but i don't get what i'm doing wrong.


I have a form with some widgets and each one is validated through kendovalidator like this



<script>
$("#text1").kendoValidator({
rules:{
ruletext1:function(input){
return $("#text1").val().length>0?true:false;
}
},messages:{
ruletext1:"you must write something in text1";
}
});

$("#text2").kendoValidator({
rules:{
ruletext2:function(input){
return $("#text2").val().length>0?true:false;
}
},messages:{
ruletext2:"you must write something in text2";
}
});
</script>


until this part everything works fine this code validates each input when some of them loses focus showing the message under the breached rule.


also i have a button that sends the information to a controller but first i need to be sure that all validations were met and here's my code.


var validateform = $("#pagoForm").kendoValidator().data("kendoValidator");



$("#btnSend").click(function(e){


if(validateform.validate()){

alert('all is valid')

}else{
alert('something's wrong')
}
});


As I understand my var validateform should return false in case of a broken rule. am i wrong?, or shoud I add the validations to the form selector?





Aucun commentaire:

Enregistrer un commentaire