ketchup-plugin icon indicating copy to clipboard operation
ketchup-plugin copied to clipboard

unbind ketchup validation from specific field if condition satisfied

Open swatijadhav opened this issue 10 years ago • 0 comments

http://stackoverflow.com/questions/22742675/jquery-ketchup-plugin-unbind-from-specific-field-if-condition-satisfied

Now, I have following scenario:

  • form has 4 address fields and one select list
  • These fields are required only if user select other than "Other Non Provider" option. (no address for "Other Non Provider")
  • I want to add the ketch-up validation for those 4 address fields depending on user-selection.

jQuery

  function bind_ketchup() {
    $(".ket-validation").ketchup({},{
      '.required_field' : 'required',
      '.validate_email' : 'email',
      '#select_state'   : 'state_list',
      '#zip_code'       : 'zip_code',
      '#list_select'    : 'lselect'
    });
  }

  $("#list_select").live("change", function(){
    var option = this.options[this.selectedIndex].text
    if(option != "Other Non-provider") {
      $(".address_block").find("input").each(function(){
        $(this).addClass("required_field");
      });
      $(".address_block").find("select").each(function(){
        $(this).addClass("select_state");
      });
      bind_ketchup()
    } else {
      $(".address_block").find("input").each(function(){
        $(this).removeClass("required_field");
      });
      $(".address_block").find("select").each(function(){
        $(this).removeClass("select_state");
      });
    }
  });

This is working fine if i select other options, but when i select "Other non provider" options again, the class is removed, but validation is still applied.

Need help to unbind or remove those ketch-up validation based on validation.

Thanks.

swatijadhav avatar Mar 31 '14 12:03 swatijadhav