Jquery Validate Plugin


Include ~/Scripts/jquery.validate.js

id="formCreate"
action="/System/Bin" method="post" novalidate="novalidate">
   

           

               

               

           

           

               
name="txtBin"
  type="text"  />
               

           
           

               

               

           

           

               

               

           

           

               

                   
               

           

Use with ajax calls - Validate within the bounded events

$(document).ready(function myfunction() {
       
        $('#btnSubmit').click(function () {
            $('#formCreate').validate({
                rules: {
                    txtBin: { required: true, number: true },

                    txtDescription: { required: true },
                    txtCardNumberLength: { required: true, number: true },
                    txtRange: { required: true, number: true }
                },
                highlight: function (element) {
                    $(element).closest('div').addClass("f_error");
                    setTimeout(function () {
                    }, 200)
                },
                unhighlight: function (element) {
                    $(element).closest('div').removeClass("f_error");
                    setTimeout(function () {
                    }, 200)
                },
                errorPlacement: function (error, element) {
                    $(element).closest('div').append(error);
                }
            }).form();

            if (!$("#formCreate").valid())
                return;

            var path = "/System/BinCreate";
            $.getJSON(path, {
                bin: $('#txtBin').val(), description: $('#txtDescription').val(),
                cardNoLength: $("#txtCardNumberLength").val(), range: $("#txtRange").val()
            }, function (data) {
                if (data.status == "success") {
                    $('#txtBin').val(""); $('#txtDescription').val("");
                    $("#txtCardNumberLength").val(""); $("#txtRange").val("");
                    indexChanged(1);
                }
            });
        });

Comments

Popular posts from this blog

Log4Net Different files in the same assembly

ටෙස්ලා

Setup Test automation with Selenium and Ruby