0

AngularJS disables (cannot submit) forms that do not have a specific action set:

<form action="">

when you create a controller. It does not have this issue when creating directive or factories.

You can see this in a plunk here:

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

Form is defined as:

<form action="" method="post">

If you delete the starting on line 6, you will be able to submit the form.

A simple solution is to define the action, but I'd rather not do this, as it is not necessary.

UPDATE

Some details can be found here on trying to get this change in Angular:

https://github.com/angular/angular.js/pull/3776

3
  • 2
    I don't understand your question please clarify it what do you mean by disable? Commented Sep 13, 2014 at 13:40
  • Updated, I meant you cannot submit the form. Commented Sep 13, 2014 at 13:46
  • I got a quick workaround :) feel free chek it out! stackoverflow.com/questions/28773057/… Commented Feb 27, 2015 at 20:08

1 Answer 1

1

You can use ng-submit to handle that.

<form ng-submit="submitForm()" method="post">
  <input name="test" value="11111111" />
  <button type="submit" name="submit" value="1">Send</button>
  <input type="submit" name="submit2" value="Send2" />
</form>

That way the form will submit normally and you must actually send the data on your submitForm function (just an example name).

Here is a quick plnkr: http://plnkr.co/edit/lwWVG0CDHSGMtMU0B8Nj?p=preview

Notice that you can submit using the buttons and also by pressing enter on the field. I hope that's what you've been asking for.

Thanks

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

6 Comments

Thank you, this works, but I am interested to know, how can you get Angular to just not meddle with the form? I've not not told Angular to do anything with the form, but it has decided it will modify it anyway. This does not seem desirable.
If you don't want your form to be handled by angular, simply put it out of the scope of your ng-app. Also I don't think you can submit a form without an action, regardless of angular.
Well, that's not very angular-ish, I strongly suggest that your rethink your angular usage in this case. You can always share more of your intentions, I still can't understand them 100%.
I'm not using Angular to do anything with the form It is a standard form to be sent by HTTP, not AJAX. Just looking for a way to get Angular to not interfere with this.
In which tag is your ng-app? The simplest way would be to put the form out of it.
|

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.