Friday, 1 July 2016

Making Active and InActive fields based on Condition

Here Call this function with boolean parameter and set it to respected field id's

function ActiveAndInActive(noneditableChoice) {
    try{
      
        document.getElementById("sponsorCode").readOnly = true;
        document.getElementById("sponsorName").readOnly = noneditableChoice;
        document.getElementById("sponsorAddress").readOnly = noneditableChoice;
        document.getElementById("sponsorActive").disabled = noneditableChoice;
        document.getElementById("primarySponsorContactName").readOnly = noneditableChoice;
        document.getElementById("primarySponsorContactNumber").readOnly = noneditableChoice;
        document.getElementById("primarySponsorEmail").readOnly = noneditableChoice;
        document.getElementById("secondarySponsorContactName").readOnly = noneditableChoice;
        document.getElementById("secondarySponsorContactNumber").readOnly = noneditableChoice;
        document.getElementById("secondarySponsorEmail").readOnly = noneditableChoice;
        $('#saveButton').attr("disabled", noneditableChoice);
    }
    catch (errorMsg) {
        console.log(errorMsg.message);
    }
}

Dynamic field validation 

 <script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script>
 
  // When the browser is ready...
  $(function() {
 
    // Setup form validation on the #register-form element
    $("#register-form").validate({
   
        // Specify the validation rules
        rules: {
            firstname: "required",
            email: {
                required: true,
                email: true
            },
           
            password: {
                required: true,
                minlength: 5
            },
             'test[]': {
                required: true,
                maxlength: 2
            },
            agree: "required",
            duration :"required",
           
        expanded :"required",
        projecttype:"required"
       
   
           
        },
       
        // Specify the validation error messages
        messages: {
            firstname: "Please enter your first name",
            lastname: "Please enter your last name",
            password: {
                required: "Please provide your feedback",
                minlength: "Your feedback must be at least 60 characters long"
            },
            contentarea : {
                 required: "Please provide a password",
                minlength: "Your password must be at least 5 characters long"
            },
             'test[]' : {
                required: "You must check at least 1 box",
                maxlength: "Check no more than {0} boxes"
            },
            email: "Please enter a valid email address",     
            expanded  : "Please enter expanded character attributes",
            selected : "Select anyone field",
            projecttype : "Please select the project type",
            dates: "myselect",
            duration :"Please enter your duration"
       
        },
       
         highlight: function(element) {
            $(element).closest('.form-group').addClass('has-error');
            $(element).closest('.datetimepicker').addClass('has-error');
        },
        unhighlight: function(element) {
            $(element).closest('.form-group').removeClass('has-error');
             $(element).closest('.datetimepicker').removeClass('has-error');
        },
       
        submitHandler: function(form) {
            form.submit();
        }
    });

  });
 
  </script>

No comments:

Post a Comment