1

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 find the code in below.

<button class="btn btn-default custom_edit" 
                            data-ng-click="orderForm.$valid && saveOrder('save')" 
                            data-ng-if="!order.IsSubmitted"
                            data-ng-model="status"
                            value="save">Save</button>
<button class="btn btn-success" 
                            data-ng-click="orderForm.$valid && saveOrder('submit')" 
                            data-ng-if="!order.IsSubmitted"
                            data-ng-model="status"
                            value="submit">Submit</button>

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

I have tried by using value & model with buttons and applied it with ng-required , however it's not working.

0

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.