placeholder issue with jQuery Validate

前端 未结 9 700
时光说笑
时光说笑 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:02

    This is generic way of validating placeholders (use following code AFTER validation logic initialization). It works by injecting custom logic into all validation methods.

    $(function () {
        $.each($.validator.methods, function (key, value) {
            $.validator.methods[key] = function () {
                var el = $(arguments[1]);
                if (el.is('[placeholder]') && arguments[0] == el.attr('placeholder'))
                    arguments[0] = '';
    
                return value.apply(this, arguments);
            };
        });
    });
    

提交回复
热议问题