jonsamwell/angular-auto-validate

submit button outside the form.

Closed this issue · 3 comments

Hi is it possible to have the submit button outside the form ?
I tried to put an ng-click on the button and $('#form_id').submit(), and it doesn't work.
Any idea ?
sorry I am a beginner with angularJS
Thank you !

Hi,

I think the submit button would have to be inside the form as the module hooks into the ng-submit directive to validate the form before calling the submit function. However, you can mimic the behavior of this and write your own directive to do this (as long as you have access to the form somehow). This is how I do it in the module - you basically call validate.validateForm(frm). Simple as that.

https://github.com/jonsamwell/angular-auto-validate/blob/master/src/config/ngSubmitDecorator.js#L17

Give a try - let me know if you have any problems.

Jon

Thank you ! I will try to implement that.
Actually I have to put the submit button outside the form, because I have a scrolling form and my button is fixed at the bottom, and I get a jumping button in ios.
I'll let you know

I managed to implement it.

  App.directive("submitOuter",function (validationManager) {
    return function (scope, element) {
      element.bind('click', function (event) {
        validationManager.validateForm($(form_element));
      });
    };
  });

thank you !