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

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.