Kendo ui dropdownlist validation mvc

Kendo ui dropdownlist validation mvc

The required validation of Kendo UI DropDownList not working some time so I'm going to share the code below for solving the same issues.




Table of Contents
      
  1. jQuery code sample.
  2. HTML 5 code sample.





Step 1 : for jquery example
//This is used for validate to KendoDropDownList.

function validateKendoDropDownList(e) {

    e.preventDefault();

    var validator = $("#formSubmit").kendoValidator().data('kendoValidator');

    var isValid = false;

    if (!(validator.validate())) {

        $("#lblMessage").text('Please select a tenant...');

        isValid = true;

    }

    return isValid;

}



$(document).ready(function () {

    $('#btnRegisterToACompany').click(function (e) {

        var isRequired = validateKendoDropDownList(e);

        if (!isRequired) {

            submtRegisterToACompany();

        }

    });

});

Step 1 : for HTML 5 code

<div id="formSubmit">
   <section class="well" style="height: 250px !important">     
       <div class="form-horizontal form-widgets col-sm-6"> 
           <label id="lblMessage" style="color:red;"></label>       
           <div class="form-group">
               <label for="language" class="control-label col-sm-4">Tenant</label>
               <div class="col-sm-8 col-md-6">
                   <input id="ddlTenants" />
               </div>
           </div>
           <div class="form-group">
               <label for="language" class="control-label col-sm-4">Company</label>
               <div class="col-sm-8 col-md-6">
                   <input id="ddlCompany" required />
               </div>
           </div>
           <div class="form-group">
               <label for="language" class="control-label col-sm-4"></label>
               <div class="col-sm-8 col-md-6 text-align_right">
                   <input type="button" value="Register to a company" id="btnRegisterToACompany" class="btn btn-primary" />
               </div>
           </div>
       </div>
    </section>
</div>



ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book