[angular.js] Input field with types (number, email etc.) and invalid initial values - bug or a feature?

4,116 views
Skip to first unread message

Pawel Kozlowski

unread,
May 28, 2012, 7:19:41 AM5/28/12
to ang...@googlegroups.com
Hi!

I was puzzled recently by the fact that 'invalid' (with a respect to
an input type) model values won't be shown in an input. Please have a
look at this jsFiddle:

http://jsfiddle.net/pkozlowski_opensource/ADukg/190/

The thing is that all the inputs are correctly marked as invalid but
the initial value won't be shown. Personally I find it a bit strange
since it doesn't give users any chance of correcting invalid values. I
guess it might get really confusing when, for example, you've got
'invalid' data loaded from a backend and those date will simply
disappear when put in a form.

What do you think?

Cheers,
Pawel

Vojta Jína

unread,
Jun 13, 2012, 2:16:52 AM6/13/12
to ang...@googlegroups.com
Kinda makes sense, what you are saying.

It would probably make more sense, to display the invalid value in the view then.
However with invalid number, you can't do that, as browser won't let you set "abc" into number input, so it's not gonna be consistent.

Honestly, I think only required-invalid makes sense for me, to have in the model.
Setting the model to something invalid from within your app sounds like an error to me.

V.



--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
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.


nal...@actifi.com

unread,
Sep 24, 2012, 2:39:08 PM9/24/12
to ang...@googlegroups.com
Personally i would prefer amplify at least attempt to display it... if the browser is the thing hiding it, at least you could do work a around by using all type="text" inputs

Currently i only use type="text" for every text/number/phone/email with pattern matching/validations... since browser support for input type is still not consistent enough for me.

nal...@actifi.com

unread,
Sep 24, 2012, 3:13:30 PM9/24/12
to ang...@googlegroups.com, nal...@actifi.com
http://jsfiddle.net/nalberg/XccGJ/

This is my work-around for current.  I just force val on the element the first time a valid value is set.

lars.g...@gmail.com

unread,
Sep 28, 2012, 10:27:40 AM9/28/12
to ang...@googlegroups.com
Same for input[url] : I have a form where an url should be entered and for convinience purposes i really like to prefill the input[url] with "http://".

Unfortunately I cannot do that except by switch back to the generic input[text] ...

Anyway - AngularJS feels great from my opinion !

Kind regards,

Lars 

Patrick Decat

unread,
Jun 3, 2014, 10:03:15 AM6/3/14
to ang...@googlegroups.com, nal...@actifi.com
Hi, in my case, I had to alter Nate's work-around, changing line 13 from:

           if(displayed == false && oldValue != undefined){

to:

           if(displayed == false && newValue != undefined){


Note: I've also updated this fiddle to use AngularJS 1.2.16 instead of 1.0.0rc4.

Regards,
Patrick.
Reply all
Reply to author
Forward
0 new messages