validate inside repeat

已查看 4,968 次
跳至第一个未读帖子

E_lexy

未读,
2012年5月28日 05:21:442012/5/28
收件人 ang...@googlegroups.com
I am trying to validate URLs inside a ng-repeat blovk, but I can't seem to find the handle to ng-show the error:

Peter Bacon Darwin

未读,
2012年5月28日 05:31:022012/5/28
收件人 ang...@googlegroups.com
Tidied it up a bit.  See if this gets you any further...


Pete

On 28 May 2012 10:21, E_lexy <alex...@gmail.com> wrote:
I am trying to validate URLs inside a ng-repeat blovk, but I can't seem to find the handle to ng-show the error:

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/52n0U5DA4hIJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

Pawel Kozlowski

未读,
2012年5月28日 07:02:462012/5/28
收件人 ang...@googlegroups.com
Hi!
Here is a working jsFiddle: http://jsfiddle.net/pkozlowski_opensource/XK2ZT/2/

There are numbers of things going on here / should be observed:

1) You can't (without using a custom directive) to dynamically
generate a name of an input :-( Indead, looking at
http://docs.angularjs.org/api/angular.module.ng.$compileProvider.directive.input
we can see that the name attribute accepts a string only;

2) Strangly enough the input of type 'url' won't show any value if the
url provided is invalid. I need to dig into this a bit as it seems to
be counter-intuitive.

3) To solve the 'dynamic name' problem you need to create an inner
form (see ng-form); the other alternative would be to write a custom
directive for this. BTW: I have found this trick with an inner form
while searching this mailing list, this topic pops up from time to
time so there are other solutions as well.

Hope this helps,
Pawel

E_lexy

未读,
2012年5月28日 09:12:562012/5/28
收件人 ang...@googlegroups.com
Thanks guys, that did it!

mvish...@gmail.com

未读,
2012年7月18日 08:43:082012/7/18
收件人 ang...@googlegroups.com

how to get inner form value using form name in AngularJS

Sebastian Sebald

未读,
2013年5月16日 16:56:512013/5/16
收件人 ang...@googlegroups.com、mvish...@gmail.com
Is it still not possible do something like "$scope.myForm.mySubForm.item[0]"?

I would like to programatically set form fields inside a ngRepeat $dirty. I know that it its possible to acces elements from scope (example: http://jsfiddle.net/EF5Jp/) and I could get the ngModelController from that element via .controller('ngModel') and then set the fields dirty and add/remove the css classes. But this seems not really clean :-/

Sebastien Cesbron

未读,
2013年5月17日 02:00:522013/5/17
收件人 ang...@googlegroups.com
Hi

The subform trick has some problems. All your inputs have the same name so the browser autocomplete feature is no more usable.

I tried to use a directive to have custom names but in my case there is a problem of propagation of validation to the main form : http://plnkr.co/edit/7RLhI4K13ugy4KIlAW2b?p=preview

My input created by the directive work well but if you remove the value the required error is not propgated to the form. I guess this is another problem of how form handle inputs but I can't overcome it.

Regards
Seb

Luciano Amodio

未读,
2013年7月11日 08:55:552013/7/11
收件人 ang...@googlegroups.com
Did you find a solution to this problem? I'm going crazy with it

matthieu...@gmail.com

未读,
2013年7月18日 08:39:192013/7/18
收件人 ang...@googlegroups.com
Up, I'm also going crazy trying to create a directive that works either with top-level and nested fields (I want to access the nested input which is inside a ng-repeat).

Nested ng-form didn't help, yet.

Thanks :)

matthieu...@gmail.com

未读,
2013年7月18日 16:07:442013/7/18
收件人 ang...@googlegroups.com
Hey, it's not that difficult finally, after hours of work :)

Nested forms is the way to go, here is a working example using a directive (with two levels of nested fields) : http://plnkr.co/edit/pg2NJSdoF1JPmHmdpRnP?p=preview

When an input is dirty and invalid, the error message is displayed.

If the user submits the form while it's invalid, it will displays every inputs with an validation error.

Llyle van Schalkwyk

未读,
2014年3月4日 17:26:562014/3/4
收件人 ang...@googlegroups.com
This is exactly what I needed, thank you!

Angular doesn't handle ngForm in a ngRepeat well from the JavaScript end, because the nested form variable has the same name as per the form name, and there is no support for dynamic form names - I tried and failed.

From the controller I was seeing:
$scope
.mainForm
.lineItemForm <---- This is the variable clash for the ngRepeat scoped form
 
Relying on a directive based approach now works well for me, because showing field validation errors are now scoped appropriately per nested form. And... using directives like this is really the more Angular way rather than creating thick controllers.
回复全部
回复作者
转发
0 个新帖子