placeholder issue with jQuery Validate

前端 未结 9 741
时光说笑
时光说笑 2020-12-31 19:10

I noticed today that we have an issue with jquery Validate when used in conjunction with placeholder text.

Example:

&
9条回答
  •  忘掉有多难
    2020-12-31 20:04

    You could script around it perhaps.

    This will remove placeholder attribute on submit, and restore them in the event of an error.

    var placeholders = {};
    $('form').validate({
       submitHandler: function(form) {
    
           $(form).find(':input[placeholder]').each(function() {
              var placeholder = $(this).attr('placeholder'); 
              placeholders[placeholder] = this;
              $(this).removeAttr('placeholder');
           });       
    
           form.submit();
       },
    
       invalidHandler: function() {
    
          $.each(placeholders, function(placeholder, element) {
              $(element).attr('placeholder', placeholder);
          });
    
       }
    
    });
    

提交回复
热议问题