View is not updated

29 views
Skip to first unread message

Yonatan Kra

unread,
Apr 8, 2014, 5:52:32 AM4/8/14
to ang...@googlegroups.com
Hi,
I have this plunkr:
http://plnkr.co/edit/YvsuLoHzX9eqb7FhDgXA?p=preview
When entering chars into the text box, the form validates correctly and it says "true".
If you use the select box before entering chars into the text box, the form validates BUT the view is not updated correctly (it still says: "false").
Any idea why?

Guilherme Meireles

unread,
Apr 8, 2014, 8:46:54 AM4/8/14
to ang...@googlegroups.com
You're using the directive "validate-message-character" on the select and on the input.
When the select is changed, if the number of characters is greater than the limit, the directive runs this "c.$setValidity('maxCharacter', false);" on the select, so the select is set to invalid and remains that way until the compose.profile gets changed.

Yonatan Kra

unread,
Apr 8, 2014, 9:01:37 AM4/8/14
to ang...@googlegroups.com
Hi,
Thanks, but I do not believe this is the case...
When select is changed, I get to the "true" statement (you can check it by adding a debug point in both "if" options.
It always comes to "true", but it changes the view only after I type something.

Guilherme Meireles

unread,
Apr 8, 2014, 9:32:49 AM4/8/14
to ang...@googlegroups.com
The ngModel changes we're triggered at different times for the input and the select.
Example:
1) Type some text 101 characters long.
2) Change the Select to 1:
3) c.$setValidity('maxCharacter', false); is run on the select
4) Type some text 99 characters long:
5) c.$setValidity('maxCharacter', true); is run on the input but not on the select that is still with $valid == false


I think this is a fix:

I just changed the scope.$watch(attrs.ngModel for attrs.$observe('validateMessageCharacter'

Yonatan Kra

unread,
Apr 8, 2014, 9:35:12 AM4/8/14
to ang...@googlegroups.com
$observe!!! of course!
I've just read about it 2 days ago... entering my 3rd month in Angular and still finding new concepts to grasp every hour...
thanks a lot!

Yonatan Kra

unread,
Apr 8, 2014, 9:42:59 AM4/8/14
to ang...@googlegroups.com
Over-excitement... I'm still getting it wrong though...
In both our plunkr's it starts false (even though it's supposed to be true, since debugging in the if statement shows it is validated as true).
In addition, changing the select changes nothing in our state, even though it passes in the "true" part of the if statement.
Looking at c.$valid or c.$invalid show as correct when playing with the select box (again, during debugging). 
Even though the value of the $valid is true and the $invalid is false, only after typing anything in the text box, it changes the value of the validity in the view.
So there's still a bug - or I'm missing something fundamental.

Guilherme Meireles

unread,
Apr 8, 2014, 9:49:34 AM4/8/14
to ang...@googlegroups.com
I think that's because the fields are required, no? So if any one of them is not set the form is considered invalid.

Yonatan Kra

unread,
Apr 8, 2014, 9:55:09 AM4/8/14
to ang...@googlegroups.com
oh :)
yeap, blushing very deeply now...
thanks :)


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/i98bPzxMQiQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages