changing the language of error message in required field in html5 contact form

后端 未结 9 953

I am trying to change the language of the error message in the html5 form field.

I have this code:



        
9条回答
  •  一个人的身影
    2020-11-27 13:46

    //Dynamic custome validation on all fields
    //add validate-msg attr to all inputs
    //add this js code
    
    $("form :input").each(function(){
                        var input = $(this);
                        var msg   = input.attr('validate-msg');
                        input.on('change invalid input', function(){
                            input[0].setCustomValidity('');
                            if(!(input[0].validity.tooLong || input[0].validity.tooShort)){
                                if (! input[0].validity.valid) {
                                    input[0].setCustomValidity(msg);
                                }
                            }
    
    
                        });
                    });
    

提交回复
热议问题