search

Home  >  Q&A  >  body text

angular.js - If the form submission does not require required verification when the hidden element is not displayed, what should I do if it needs to be verified when it is displayed?

As shown in the title, there is a form in which a p is controlled by a check box. If checked, the input element under the p will be displayed, and verification is required. If not checked, there is no need to verify hidden elements when the form is submitted. In the case of ng-if, even if validator="[required]" is added to the displayed elements, they will not be verified after being displayed. In the case of ng-hide, validator="[required]" will also perform required verification on the hidden elements.

Supplement: If you write the required attribute directly in the input tag, it seems that the desired effect can only be achieved under IE.

曾经蜡笔没有小新曾经蜡笔没有小新2779 days ago837

reply all(5)I'll reply

  • ringa_lee

    ringa_lee2017-05-15 17:10:25

    It would be great if you write js directly for verification,

    reply
    0
  • PHP中文网

    PHP中文网2017-05-15 17:10:25

    I have never used ang_js, but I suggest that the author directly wraps an if judgment outside the section that verifies the hidden field input in the method it uses to verify the form. This should be able to achieve the minimum modification requirements without affecting the overall performance. Verification style, hope it helps you

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-15 17:10:25

    ng-required

    reply
    0
  • PHP中文网

    PHP中文网2017-05-15 17:10:25

    I always use ng-if, no problem. form submission.

    <form name="myForm" novalidate>
        <p ng-class="{'error': myForm.name.$invalid}" ng-if="show">
            <input type="text" name="name" required>
        </p>
    </form>

    Anything written in the controller should be returned when the form verification fails.

    reply
    0
  • 怪我咯

    怪我咯2017-05-15 17:10:25

    The hidden form is set to non-required

    reply
    0
  • Cancelreply