AngularJS: Prevent hidden form fields being validated

前端 未结 3 1237
Happy的楠姐
Happy的楠姐 2021-01-31 02:08

What is the best way of preventing hidden form fields being validated in AngularJS?

3条回答
  •  野性不改
    2021-01-31 02:35

    I initially missed the built-in ngRequired directive. There is a required tag as well, which confused me.

    Now, we can use the same logic (which we used to hide the element) to set the ngRequired false.

    Here is an example practical usecase: I want to ask married people the number of children they have, but, if they are not married, simply hide the field about children.

    Marital status:
    Number of children:
    (for testing) Is this form correctly filled? {{form.$valid}}

提交回复
热议问题