Force to show invalid-feedback in Bootstrap 4

后端 未结 2 2029
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 04:01

Let\'s say I have HTML like this:

...
2条回答
  •  北恋
    北恋 (楼主)
    2021-02-05 04:46

    There are better ways.

    1) Look into a was-validated class, that you can set on the form like so

    When set on the form it displays validation feedback and also colorcodes the input field.

    Just add it conditionally on your form, when validation failed on the server side.

    2) Or you can use some JavaScript to be in control of what is displayed. You can add this class dynamically

    $('form').addClass('was-validated');
    

    and you can also dynamically check if the form is valid like so

     if ($('form').checkValidity()) {...
    

提交回复
热议问题