Input required - conditional

2,984 views
Skip to first unread message

Johan Steenkamp

unread,
Mar 5, 2012, 3:43:05 AM3/5/12
to ang...@googlegroups.com
How can I make required optional for a form input. Scenario - radio button yes/no enables a text field, if field is enabled it is required. nd:disabled works great for enable/disable however even if disabled the form filed is still seen as required by the validation.

Thanks

Johan Steenkamp

unread,
Mar 5, 2012, 3:43:32 PM3/5/12
to ang...@googlegroups.com
If it was possible to know when a template has completed loading (not using ng:include - using $route) using $(selector).remove() would work perfectly since the elements can have required attribute. If removed they have no effect on validation.

Johan

Igor Minar

unread,
Mar 5, 2012, 4:45:30 PM3/5/12
to ang...@googlegroups.com
just bind to required attribute: http://jsfiddle.net/CHVbb/208/

--
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/-/PTHVPLK3RBgJ.

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.

Johan Steenkamp

unread,
Mar 6, 2012, 2:45:51 AM3/6/12
to ang...@googlegroups.com
Doh - tried that but left out the {{ }} binding - no wonder it did not work!

Thanks

Johan


Robert B. Weeks

unread,
Apr 12, 2012, 9:10:17 AM4/12/12
to ang...@googlegroups.com
Hello -

This seems to not work anymore - is there an alternative way to set the required bit conditionally?

This works with the setting of it, but does not remove it if the condition is met.

http://jsfiddle.net/vaiism/KgYeF/

Thanks!


On Mar 5, 2012, at 4:45 PM, Igor Minar wrote:

> just bind to required attribute: http://jsfiddle.net/CHVbb/208/
>
> On Mon, Mar 5, 2012 at 12:43 PM, Johan Steenkamp <johan.s...@gmail.com> wrote:
> If it was possible to know when a template has completed loading (not using ng:include - using $route) using $(selector).remove() would work perfectly since the elements can have required attribute. If removed they have no effect on validation.
>
> Johan
>
>
> On Monday, March 5, 2012 9:43:05 PM UTC+13, Johan Steenkamp wrote:
> How can I make required optional for a form input. Scenario - radio button yes/no enables a text field, if field is enabled it is required. nd:disabled works great for enable/disable however even if disabled the form filed is still seen as required by the validation.
>
> Thanks

--
Robert B. Weeks


Johan

unread,
Apr 12, 2012, 3:34:31 PM4/12/12
to ang...@googlegroups.com
In 1.0.0rc4 it change to ng-required so you need

ng-required="shouldBeRequired"


These also changed:

ng-multiple
ng-selected
ng-checked
ng-disabled
ng-required

Peter Bacon Darwin

unread,
Apr 12, 2012, 3:45:14 PM4/12/12
to ang...@googlegroups.com
Why is this not in the change log?  Or am I not looking in the right place?
Does ng-require work in the same way as require?  I.E. do you have to provide a value for the attribute - <input ng-require> or <input ng-require="true">?  From playing with the fiddle it appears this is not so.
Pete

--
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/-/m4AeAFNFPLAJ.

Johan

unread,
Apr 12, 2012, 3:56:17 PM4/12/12
to ang...@googlegroups.com
I did not see it in change log either - found out after posting it as a "bug"


Pete

To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.

Peter Bacon Darwin

unread,
Apr 12, 2012, 4:17:26 PM4/12/12
to ang...@googlegroups.com
Great. Thanks.  At least that is consistent now.
Pete

To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/s5A95Q3fjK0J.

To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.

Robert B. Weeks

unread,
Apr 12, 2012, 4:37:04 PM4/12/12
to ang...@googlegroups.com
Hey Johan -

> In 1.0.0rc4 it change to ng-required so you need
>
> ng-required="shouldBeRequired"
>
> http://jsfiddle.net/johans/KgYeF/4/

doh! - that is how they were in our code originally (0.10.5) and I couldn't seem to get to work. Now they do. Must be sunspots.

Thanks for sending and sending the commit/bug for reference..


> These also changed:
>
> ng-multiple
> ng-selected
> ng-checked
> ng-disabled
> ng-required
>
>
> On Friday, April 13, 2012 1:10:17 AM UTC+12, Robert B. Weeks wrote:
> Hello -
> This seems to not work anymore - is there an alternative way to set the required bit conditionally?
>
> This works with the setting of it, but does not remove it if the condition is met.
>
> http://jsfiddle.net/vaiism/KgYeF/
>
> Thanks!

--
Robert B. Weeks


Reply all
Reply to author
Forward
0 new messages