johannesjo / ng-fab-form

Convenient forms for Angular with no extra markup? Fabulous!
https://johannesjo.github.io/ng-fab-form
MIT License
172 stars 25 forks source link

Validation trigger on ng-click instead of submit #91

Closed baskaranr closed 7 years ago

baskaranr commented 7 years ago

Hi,

I have two actions in my form "save", "save and approve". So i want to trigger validation manually in both actions instead of form-submit. Please do the needful.

Thanks, Baskar

johannesjo commented 7 years ago

You can use <button type="button"></button> together with this approach to manually trigger a form submit: http://stackoverflow.com/questions/16003188/can-i-trigger-a-form-submit-from-a-

Does this help you?

baskaranr commented 7 years ago

Thanks for the quick reply. I tried the solutions mentioned in the stackoverflow link. But those solutions doesn't trigger fab-form validations.

johannesjo commented 7 years ago

If you trigger the submit, the validation is triggered, isn't it?

baskaranr commented 7 years ago

yes its working via html.

<form id="item_form" name="item_form" class="form-horizontal" role="form" ng-submit="saveItem()">

but its not working while invoke submit from controller code as mentioned in stackoverflow answers.

johannesjo commented 7 years ago

Oh that's interesting! I'll have to check this you Out. Could you by any chance provide a plunkr?

baskaranr commented 7 years ago

Sorry. I have been using this plugin part of project and couldn't able to extract the form code in plunkr

On Oct 12, 2016 10:04 PM, "Johannes Millan" notifications@github.com wrote:

Oh that's interesting! I'll have to check this you Out. Could you by any chance provide a plunkr?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/johannesjo/ng-fab-form/issues/91#issuecomment-253266271, or mute the thread https://github.com/notifications/unsubscribe-auth/ADSTZio2XSdjOkE0tDvMpEfBjqs30AnDks5qzQwogaJpZM4KUZVQ .

johannesjo commented 7 years ago

Hey there. I checked again. To trigger the validation messages (at least with the default validations-tempalte) you can set form controllers $triedSubmit property to true. Here is an example: http://plnkr.co/edit/jIGCxuXGIPkB60ZJP0jS?p=preview

baskaranr commented 7 years ago

Hi,

Thanks for the plnkr. Its very closer to my requirement. The submit doesn't call the respective method if validation fails. In triedsubmit case we have to handle it as like fake submit - 2.

Please check the modified plunkr. http://plnkr.co/edit/qlOgr6n6NPtujff8Wzg8?p=preview

johannesjo commented 7 years ago

Sorry, Im not sure what the issue is. can you elaborate further? if(!form.$valid) { return;} does not solve your problem? Why not?

baskaranr commented 7 years ago

It solves the problem. but submit button click its handled without this code block.

johannesjo commented 7 years ago

Sorry, you have to explain a little better what the problem is, you're facing.

baskaranr commented 7 years ago

sorry, it works as expected. Please go through this fiddle for reference. [Fake submit 1 click and Fake submit 2 click]

http://plnkr.co/edit/qlOgr6n6NPtujff8Wzg8?p=preview

johannesjo commented 7 years ago

I'm glad, that it works!