2016-09-19 95 views
0

我是AngularJS的初学者。所以我很困惑这种语言。请检查我的代码:如何在AngularJS的一个提交按钮中验证两个表单?

<form class="form-horizontal" ng-submit="productFormForm.$valid && submitProductForm()" novalidate="" name="productFormForm"> 
    <label for="from_id_dropdown">Templates</label> 
    <select class="form-control" name="from_id_dropdown" id="from_id_dropdown" ng-model="formData.form_id" ng-change="getDropdownOptions(formData.form_id)" ng-options="option.id as option.name for option in forms_dropdown.availableOptions" required=""> 
     <option value="">Select Template</option> 
    </select> 
    <div ng-show="productFormForm.$submitted || productFormForm.from_id_dropdown.$touched" class=""> 
     <span style="color:red;" ng-show="productFormForm.from_id_dropdown.$error.required">Template is required.</span> 
    </div> 
</form> 

<form class="form-horizontal" ng-submit="attributeForm.$valid && submitForm()" novalidate="" name="attributeForm"> 
    <label class="tooltip-demo">Label</label> 
    <input type="text" name="attribute_lebel" ng-model="attr_value.label" class="form-control" placeholder="Label Name" required=""> 
    <div ng-show="attributeForm.$submitted || attributeForm.attribute_lebel.$touched" class=""> 
     <span class="text-danger" ng-show="attributeForm.attribute_lebel.$error.required">Label is required.</span> 
    </div> 


    <button class="btn btn-w-m btn-success" type="submit">Save</button> 
</form> 

下面是两个表单productFormFormattributeForm但一个提交按钮是第二个形式。我想验证这两个字段都是空白的。 example

或HTML您的按钮后,添加<span> - -

+0

这一点,你sshould使用ngMessages,所以当你键入或触摸你输入他们将显示消息错误 –

+0

是否有2个表单的原因? –

回答

0

可以使用JS验证两种形式

<span ng-show="attributeForm.attribute_lebel.$error.required || productFormForm.from_id_dropdown.$error.required"> Form not valid</span> 
+0

您只需禁用该按钮。但是我想在点击提交按钮时显示错误信息 – Chinmay235

+0

我已经更新了我的答案 – Disha

相关问题