1

Is there any easy way to submit form using angularjs without angular ajax call or old school style by adding action="xxxx" attribute to form?

An example would be a huge form where assigning model for each field is not an option or either sending it with ajax call as well, but since form got inside ng-app I can't find any other solution on how to submit it. Forgot to say, that adding action to all sorts of forms is bad idea as well(in my case).

I've tried combining it with jQuery, but I'm probably doing that worng as well.

<form name="ticketForm" method="post" enctype="multipart/form-data" ng-controller="TicketCtrl" ng-submit="submitForm()">
...
</form>

And script part would be:

var Ticket = angular.module('ticket', []);

Ticket.controller('TicketCtrl', ['$scope', function($scope)
{
    $scope.submitForm = function()
    {
        $('form[name="ticketForm"]').submit();
    };
}]);

The form is submited, but in console I see, that angular doesn't like it much,

Error: $apply already in progress
1
  • angular directly does not support native submits you have to use model and ajax to submit the form Commented Sep 25, 2013 at 11:35

1 Answer 1

6

I think it is leading to a recursive call(because since you are calling the submit on a jQuery wrapper object it will again call the form submit handler), try to call the submit method of the dom element instead

$('form[name="ticketForm"]')[0].submit();
Sign up to request clarification or add additional context in comments.

5 Comments

Yep, that solved the issue with the error, but can it be done with angular only and without steps named above?
@Eugene what are you trying to do here?
@Eugene if you are trying to do a normal page submit there there is no need for the submit handler itself
@Eugene <form name="ticketForm" method="post" enctype="multipart/form-data" ng-controller="TicketCtrl"> should submit the form if a submit button is clicked
maybe we discuss in chat? chat.stackoverflow.com/rooms/38018/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.