How to change the default message of the required field in the popover of form-control in bootstrap?

前端 未结 4 937
别跟我提以往
别跟我提以往 2020-12-02 07:11
 

相关标签:
4条回答
  • 2020-12-02 07:47

    And for all input and select:

    $("input[required], select[required]").attr("oninvalid", "this.setCustomValidity('Required!')");
    $("input[required], select[required]").attr("oninput", "setCustomValidity('')");
    
    0 讨论(0)
  • 2020-12-02 07:56

    You can use setCustomValidity function when oninvalid event occurs.

    Like below:-

    <input class="form-control" type="email" required="" 
        placeholder="username" oninvalid="this.setCustomValidity('Please Enter valid email')">
    </input>
    

    Update:-

    To clear the message once you start entering use oninput="setCustomValidity('') attribute to clear the message.

    <input class="form-control" type="email"  required="" placeholder="username"
     oninvalid="this.setCustomValidity('Please Enter valid email')"
     oninput="setCustomValidity('')"></input>
    
    0 讨论(0)
  • 2020-12-02 07:57

    Combination of Mritunjay and Bartu's answers are full answer to this question. I copying the full example.

    <input class="form-control" type="email"  required="" placeholder="username"
     oninvalid="this.setCustomValidity('Please Enter valid email')"
     oninput="setCustomValidity('')"></input>
    

    Here,

    this.setCustomValidity('Please Enter valid email')" - Display the custom message on invalidated of the field

    oninput="setCustomValidity('')" - Remove the invalidate message on validated filed.

    0 讨论(0)
  • 2020-12-02 08:01

    $("input[required]").attr("oninvalid", "this.setCustomValidity('Say Somthing!')");

    this work if you move to previous or next field by mouse, but by enter key, this is not work !!!

    0 讨论(0)
提交回复
热议问题