Friday, November 9, 2012

Kendo UI Validation for Dublicate Value Checking


I am faced a problem with validation for duplicate value checking from server using json. My code is runing fine in each click but error message show in second click(One click in side text box put value then click out side the text box - that time code execute but error message show . again i click in that text box and again click out side text box ,again my code run and this time error message show) . Please find my mistake and help me to show validation message in single escape or single click of text box.
Now I solve by adding ajax async clode in the to  of the javascript. We get success if you use this.

script language="javascript" type="text/javascript"

//KendoUi Validation
    var validatable = $("#ApplicationNo").kendoValidator({
        onfocusout: true,
        onkeyup: true,
        rules: {
            ApplicationNo: function (input) {
                $.post("/Home/CheckAppNo", 
               { ApplicationNo: $("#ApplicationNo").val() }, 
               function (data) { b1 = data; })
                return b1;
              }

        },

        messages: {
            ApplicationNo: "Already Exist"
        }
    }).data("kendoValidator");

   var validatable = 
       $(".k-content").kendoValidator().data("kendoValidator");
 


script language="javascript" type="text/javascript"

//KendoUi Validation

        $.ajaxSetup({ async: false }); 
 
    var validatable = $("#ApplicationNo").kendoValidator({
        onfocusout: true,
        onkeyup: true,
        rules: {
            ApplicationNo: function (input) {
                $.post("/Home/CheckAppNo", 
              { ApplicationNo: $("#ApplicationNo").val() }, 
                function (data) { b1 = data; })
                return b1;
            }

        },

        messages: {
            ApplicationNo: "Already Exist"
        }
    }).data("kendoValidator");

   var validatable = 
       $(".k-content").kendoValidator().data("kendoValidator");

C # Code

    public JsonResult CheckAppNo(string ApplicationNo)
    {
        bool IsOk = projectRepository.CheckAppNumber(ApplicationNo);
        return Json(IsOk, JsonRequestBehavior.AllowGet);
        //return new JsonResult { Data = IsOk };
    }
 
 

Html

< input type="text" id="ReferredBy" name="ReferredBy" class="k-textbox" required />
 
 

No comments:

SQL Optimization

  SQL Optimization  1. Add where on your query  2. If you remove some data after the data return then remove the remove condition in the sel...