Angular JS: Validate form fields before submit

前端 未结 1 1920
别那么骄傲
别那么骄傲 2020-12-13 03:56

I\'m building an Angular JS app with a 2-step form. It\'s really just one form, but uses JavaScript to hide the first panel and show the second when the user clicks the \'ne

1条回答
  •  隐瞒了意图╮
    2020-12-13 04:54

    I suggest to use sub-forms. AngularJS supports putting one form inside another, and validity is propagated form lower form to upper;

    Here is example: http://plnkr.co/edit/SruBmlGZZtbwiU8cktAp?p=preview

    Here is some code so you can grasp the idea:

      

    Step 1: Enter some general info

    Name:

    Step 2: Final info

    Phone:
    Validation status:
    Whole form valid? {{myform.$valid}}
    Step1 valid? {{step1form.$valid}}
    Step2 valid? {{step2form.$valid}}

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