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

Validation with custom rule for data in either AutoComplete or DropDownList

1 Answer 225 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 1
Sean asked on 23 Oct 2013, 04:22 PM
How can I validate whether input has been entered in an AutoComplete or a selection has been made in a DropDownList. If neither is true then it should fail validation. I'm just figuring out the Kendo Validation and if there was a length requirement maybe I'd be on the right track. Can someone suggest a successful way to validate this scenario?

Here's where I started:
<div id="cboSearchStringValidate1">
    <input type="search" id="cboSearchString1AC" />
    <input id="cboSearchString1DDL" />
</div>

$("#btnSearch").click(function () {                                         alert('start to validate');                                             $("#cboSearchStringValidate1").kendoValidator({
rules: {
                                                       customruleSearchStrings1: function (input) {                                if (cboSearchString1AC.length == 0 && $(cboSearchString1DDL).val == ""){
 return input.val() === "true";
}                                                           return true;                                                       }
},                                                   messages: {                                                       customruleSearchStrings1: "Search must not be empty"                                                 }                                               });                                               alert('validate checked');                                           
                                            }
                                           );
I think this needs to be in here somewhere, but not sure if I have the whole thing put together properly.
var validator1 = $("#cboSearchStringValidate1").kendoValidator().data("kendoValidator");
if (!validator1.validate()) {
    alert("validated search strings 1");
    alert('yes, we are valid');
}
else {
    alert("no such luck");
                                               }
Thanks in advance for enlightening me ;)

1 Answer, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 25 Oct 2013, 12:28 PM
Hello Todd,

You will need to initialize the Kendo UI Validator, before you click the button for validation. Please check the following example, showing a possible implementation:

http://jsbin.com/EdOcayI/2/edit
 
Regards,
Kiril Nikolov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
General Discussions
Asked by
Sean
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Share this question
or