AngularJS验证无效

时间:2015-08-04 16:19:51

标签: angularjs

我已经创建了一个带有angularjs的表单,但是当我第一次加载页面时,表单开始无效,整个表单变为红色。我已添加" novalidate"形式和"要求"输入,但整个表格开始无效和红色。

1 个答案:

答案 0 :(得分:0)

当您单击提交按钮而不输入任何值时,从此程序中将发生验证

<form name="product_form" class="form-horizontal" role="form" novalidate>
            <div class="control-group" ng-class="{true: 'error'}[submitted && product_form.emailid.$invalid]">
                <form-element label="Name" mod="product">
                    <input type="text" class="form-control" name="name" placeholder="name" ng-model="product.name" ng-disabled="product.id" required/>
                    <span class="help-block" ng-show="submitted && product_form.name.$error.required"> Please enter name </span>
                </form-element>

                <form-element label="Emailid" mod="product">
                    <input type="email" name="emailid" class="form-control" placeholder="emailid" ng-model="product.emailid" required>
                    <span ng-show="submitted && product_form.emailid.$error.required" class="help-block">Please enter emailid</span>
                </form-element>

                <form-element label="Password" mod="product">
                    <input type="password" name="password" class="form-control" placeholder="password" ng-model="product.password" required/>    
                    <span ng-show="submitted && product_form.password.$error.required" class="help-block"> Please enter password </span>
                </form-element> 
            </div>  

            <div class="space"></div>
            <div class="space-4"></div>  

            <div class="modal-footer">  

                <a class="btn btn-sm" ng-click="cancel()" ><i class="ace-icon fa fa-reply"></i> Cancel </a>

                 <button ng-click="saveProduct(product);submitted=true"
                            ng-enabled="product_form.$invalid || enableUpdate"
                            class="btn btn-sm btn-primary ng-binding"
                            type="submit">
                        <i class="ace-icon fa fa-check"></i>Submit
                 </button>


            </div>
     </form>