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

Kohjah Breese
  • 4,008
  • 6
  • 32
  • 48

1 Answers1

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

Fedaykin
  • 4,482
  • 3
  • 22
  • 32
  • 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. – Kohjah Breese Sep 13 '14 at 14:02
  • 1
    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. – Fedaykin Sep 13 '14 at 14:58
  • 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%. – Fedaykin Sep 13 '14 at 15:03
  • 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. – Kohjah Breese Sep 13 '14 at 15:11
  • 1
    In which tag is your `ng-app`? The simplest way would be to put the form out of it. – Fedaykin Sep 13 '14 at 15:25
  • Yes, this is the simplest. The ng-app is on my html tag. I can't move it as there are a couple of items that depend on it. It seems the best option is to just specify the action. Thanks for your time. – Kohjah Breese Sep 13 '14 at 15:29