You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Yep, this issue is still around (as of 1.2-rc.2). I'll test on rc3 and update this ticket.
EDIT: Confirmed, this is still broken in rc3. Relevant Plnkr
UPDATE: I tried my hand at a fix (adding 'submit' trigger to ngForm's input elements (onclick)), but I know I'm going about it the wrong way. Here's what I have so far.
From the looks of it, it cannot work as <ng-form> or <div ng-form> is not a form element, and so will never fire the 'submit' event. It's prettfy fiddly to emulate form behavior completely. There was a section in the angular docs about this, but I can't seem to find it:
Pressing enter in a text field -> submit
Pressing space or enter when a input or button with type=submit has focus -> submit
clicking a button or input with type=submit -> submit
EDIT: I ended up working out my particular use case by giving individual forms interpolated names (as indicated in this stackoverflow answer) and validating each one individually.
Directive fix (no jQuery or any other dependencies):
With this directive, any ngForm will automatically call any input | button with type="submit".
It also fixes ngSubmit to work with ngForm (same functionality, you can even omit ng-click on your button)
ngForm directive useage: (Automatically calls any input/button with type="submit")
This would be nice to have built-in to Angular, since like most of you are saying, ngForm without ngSubmit or even the Enter key working (and hitting a submit) is kind of pointless.
I'm going to see if I can potentially make a Pull-Request for this issue.
@mcpDESIGNS you can make pull request and team will consider if they can make it built-in. But before it, please consider to add tests and please don't use "ng" prefix for custom directives, it's kind of "reserved" :)
@e-oz I'll take a look, doesn't seem like it'd be too bad to tackle natively.
Oh of course! I never use ng, I simply wanted to add it on-top of the original ngForm directive, without having to add another. I probably should of just extended it now that I think about it :)
A. The problem is if there are multiple buttons, the first will be the submit button, even it has no type=submit attribute. You can see it here. So I replaced the if ($current.type.toLowerCase() === 'submit') { width if ($current.getAttribute('type') && $current.getAttribute('type').toLowerCase() === 'submit') {.
Another problem that there is no $submitted property and no ng-submitted class to the ng-form. The class issue I solve with adding $element.addClass('ng-submitted'); after the line $parse($attrs.ngSubmit)($scope);. But I couldn't solve the $submitted issue.
This is very strange based on the fact that the ng-form object has property $submitted which is false all the time and I couldn't set it to true.
I tried:
$element.$submitted = true; - no effect.
$setSubmitted(); - error $element.$setSubmitted is not a function
Very nice, you're totally right button by default has type="submit" so we definitely need to be using .getAttribute('type') I'll have to update the Repo.
I'll have to look into the other issue, you might just need to set some other type of variable to temporarily let everything know it was "submitted".
It might have something to do with the fact that there's a ng-repeat creating all these ng-forms in your example too. I'm playing with it now.
Activity
btford commentedon Aug 24, 2013
As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.
Please try the newest versions of Angular (
1.0.8and1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.Thanks!
nelsonpecora commentedon Oct 21, 2013
Yep, this issue is still around (as of 1.2-rc.2). I'll test on rc3 and update this ticket.
EDIT: Confirmed, this is still broken in rc3. Relevant Plnkr
UPDATE: I tried my hand at a fix (adding 'submit' trigger to ngForm's input elements (onclick)), but I know I'm going about it the wrong way. Here's what I have so far.
feat(ngForm): add ngSubmit support
jdrake commentedon Nov 11, 2013
+1 I'm seeing this in 1.2.0.
nelsonpecora commentedon Nov 27, 2013
Confirmed, this is happening in 1.2.2.
Narretz commentedon Nov 28, 2013
From the looks of it, it cannot work as
<ng-form>or<div ng-form>is not a form element, and so will never fire the 'submit' event. It's prettfy fiddly to emulate form behavior completely. There was a section in the angular docs about this, but I can't seem to find it:Pressing enter in a text field -> submit
Pressing space or enter when a input or button with type=submit has focus -> submit
clicking a button or input with type=submit -> submit
mdedetrich commentedon Jan 27, 2014
I can confirm this issue for 1.2.9, using ng-form instead of form as an element means that ng-submit will not work
23 remaining items
LeleDev commentedon Sep 16, 2015
+1
fferraris commentedon Sep 16, 2015
+1
itslikegood commentedon Sep 22, 2015
+1
filipesilva commentedon Sep 22, 2015
Also having this issue.
EDIT: I ended up working out my particular use case by giving individual forms interpolated names (as indicated in this stackoverflow answer) and validating each one individually.
For instance (using
controllerAs: 'vm')I didn't bother to give each form control interpolated names though, since they are objects within the form.
e-oz commentedon Sep 29, 2015
ng-submit still doesn't work with ng-form (so ng-form is not just alias of form).
MarkPieszak commentedon Oct 22, 2015
Here's an update for everyone, since I ran into this issue myself.
This is still an issue in version
1.4.7.Here's the directive code on github (no jQuery depedencies or anything)
DEMO here
Directive fix (no jQuery or any other dependencies):
With this directive, any
ngFormwill automatically call any input | button withtype="submit".It also fixes ngSubmit to work with ngForm (same functionality, you can even omit ng-click on your button)
ngForm directive useage: (Automatically calls any input/button with type="submit")
ngSubmit functionality fix for ngForm:
This would be nice to have built-in to Angular, since like most of you are saying, ngForm without ngSubmit or even the Enter key working (and hitting a submit) is kind of pointless.
I'm going to see if I can potentially make a Pull-Request for this issue.
e-oz commentedon Oct 22, 2015
@mcpDESIGNS you can make pull request and team will consider if they can make it built-in. But before it, please consider to add tests and please don't use "ng" prefix for custom directives, it's kind of "reserved" :)
MarkPieszak commentedon Oct 22, 2015
@e-oz I'll take a look, doesn't seem like it'd be too bad to tackle natively.
Oh of course! I never use
ng, I simply wanted to add it on-top of the originalngFormdirective, without having to add another. I probably should of just extended it now that I think about it :)moshfeu commentedon Mar 30, 2016
The demo link is not working so I made a new one on bin
MarkPieszak commentedon Mar 30, 2016
@moshfeu Sorry about that, just fixed the link to it, the Demo should work now!
ngForm fix demo
moshfeu commentedon Mar 30, 2016
A. The problem is if there are multiple buttons, the first will be the
submitbutton, even it has notype=submitattribute. You can see it here. So I replaced theif ($current.type.toLowerCase() === 'submit') {widthif ($current.getAttribute('type') && $current.getAttribute('type').toLowerCase() === 'submit') {.Another problem that there is no
$submittedproperty and nong-submittedclass to theng-form. The class issue I solve with adding$element.addClass('ng-submitted');after the line$parse($attrs.ngSubmit)($scope);. But I couldn't solve the$submittedissue.This is very strange based on the fact that the
ng-formobject has property$submittedwhich is false all the time and I couldn't set it totrue.I tried:
$element.$submitted = true;- no effect.$setSubmitted();- error$element.$setSubmitted is not a functionAny suggestions?
Thanks
MarkPieszak commentedon Mar 30, 2016
Very nice, you're totally right
buttonby default hastype="submit"so we definitely need to be using.getAttribute('type')I'll have to update the Repo.I'll have to look into the other issue, you might just need to set some other type of variable to temporarily let everything know it was "submitted".
It might have something to do with the fact that there's a
ng-repeatcreating all these ng-forms in your example too. I'm playing with it now.moshfeu commentedon Mar 31, 2016
Finally I got this!
I added
$scope[$attrs.ngForm].$submitted = true;in the submit function and it's works.I sent a Pull Request. Tell me if it's OK.
Thanks!
MarkPieszak commentedon Mar 31, 2016
We are all set :) @moshfeu Thanks for the PR.
Updated the repo : https://github.com/MarkPieszak/ngForm-handle-Enter-Keypress
molerat619 commentedon Sep 7, 2016
Thank you. The PR works for me.