Force to show invalid-feedback in Bootstrap 4

后端 未结 2 2030
爱一瞬间的悲伤
爱一瞬间的悲伤 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

    <form action="..." class="was-validated" method="POST" novalidate>
    

    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()) {...
    
    0 讨论(0)
  • 2021-02-05 04:48

    Use display classes to display it manually for example d-block

    use it like so

    <div class="valid-feedback d-block"> 
    

    or

    <div class="invalid-feedback d-block">
    

    Find more in documentation

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