Skip to content Skip to sidebar Skip to footer

Conditional Required Validation With Buttons In AngularJS

I having two buttons as Save and Submit and some of the drop-downs and text-boxes. There is need to validate some of the fields on click of Submit, not on click of Save. Please fin

Solution 1:

Using input type as 'submit', validation can be maintained as well as other function can be also called as form is valid.

<input type="submit" value="Save"
                            data-ng-click="isSave = true; orderForm.$valid && saveOrder('save')" 
                            data-ng-model="isSave" 
                            data-ng-show="!order.IsSubmitted"/>
<input type="submit" value="Submit"
                            data-ng-click="isSave = false; orderForm.$valid && saveOrder('submit')" 
                            data-ng-model="isSave"  
                            data-ng-show="!order.IsSubmitted"/>

<input type="text" class="form-control" name="_requisition" placeholder="Requisition"
                            data-ng-model="order.Requisition"
                            data-ng-trim="true"
                            maxlength="100"
                            data-ng-required="isSave"/>

So by this way, we can easily set model value on button click at run time as well as can validate form.


Post a Comment for "Conditional Required Validation With Buttons In AngularJS"