$dirty flag being set when form is loaded

3,821 views
Skip to first unread message

Paul Bradford

unread,
Jan 10, 2013, 4:39:23 PM1/10/13
to ang...@googlegroups.com
Hi all.  I have a typical angular form & control that I am having a problem in that the $dirty flag is being set to true (and the $pristine flag set to false) when the form is populated from the controller during the initial load.  The control that is causing the issue is a Select element (partial html below) that is using the ui-select2 directive form the Angular-UI library.

<select ui-select2  data-ng-required="!model.Waiver" data-ng-model="model.AdvisorId" data-placeholder="Advisor">
                    <option ng-repeat="ao in advisorOptions" value="{{ao.UserId}}">{{ao.LastFirst}}</option>
</select>

If I remove the 'ui-select2' directive, that the flags are $dirty and $pristine flags are properly set.  Anyone else encountered this?  Any suggestions for handling this?


Vili

unread,
Feb 12, 2013, 4:24:55 AM2/12/13
to ang...@googlegroups.com
Hi Paul,

I faced the same issue, the form gets dirty because in your data-ng-model="model.
AdvisorId" the value is originally an Integer but after page load and rendering the data type of your ng-model becomes a string value which makes your form dirty.
To solve this use below html code for your dropdown :-


<select ui-select2  data-ng-required="!model.Waiver" data-ng-model="model.AdvisorId" ng-options="ao.UserId as ao.LastFirst for ao in advisorOptions" data-placeholder="Advisor">
                    <option></option>
</select>

Here keep a blank option tag( <option></option> ) so that if no value is selected in your drop down it will show your data-placeholder string in it.


Thanks & Regards,

Vili

Brett Atoms

unread,
Mar 17, 2013, 1:50:52 PM3/17/13
to ang...@googlegroups.com
I'm having this same issue but I need to use the ui-select2 directive on an <input> which doesn't have any <option> tags.  How would I make sure my form is $pristine in this case?

Brett

Jaymes Bearden

unread,
Mar 27, 2013, 2:50:30 PM3/27/13
to ang...@googlegroups.com
I am also encountering this exact problem.

Has any one found any solutions?

Brian Kelley

unread,
Apr 2, 2013, 11:24:51 AM4/2/13
to ang...@googlegroups.com
I am having the same issue, on a new form using a select element with ng-options works but is unsupported by ui-select2.  On an edit form, using ng-options again works but displays the incorrect selection even though when the select box is opened the correct option is selected and the form resets to the correct selection.  

Brian Kelley

unread,
Sep 17, 2013, 12:07:54 PM9/17/13
to ang...@googlegroups.com
Matt Walker's reply made this work quite well for me... https://github.com/angular-ui/ui-select2/issues/6 

Inna Bauman

unread,
Aug 20, 2014, 10:43:01 AM8/20/14
to ang...@googlegroups.com
I have the same problem but i can't use ng-option because i have also <optgroup> so if any one can help me :)
Reply all
Reply to author
Forward
0 new messages