Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model starts as "dirty" #199

Closed
Scipionh opened this issue Sep 6, 2016 · 5 comments
Closed

Model starts as "dirty" #199

Scipionh opened this issue Sep 6, 2016 · 5 comments

Comments

@Scipionh
Copy link

Scipionh commented Sep 6, 2016

I have the following input :

<input type="text"
class="validate"
[(ngModel)]="dateX"
[textMask]="{mask: [/\d/, /\d/, '.', /\d/, /\d/, '.', /\d/, /\d/, /\d/, /\d/], placeholderChar: '\u2000'}"
name="dateX"
ngControl="dateX"
#dateX="ngModel" />

however, when the page loads, it is loaded with dirty. After a quick look at the code, it seems to come from the writeValue.
Any reason why it isn't loaded with dirty=false ?

@Scipionh Scipionh changed the title Using a Using a date mask makes the input loading dirty Sep 6, 2016
@andyrue
Copy link
Contributor

andyrue commented Sep 6, 2016

Strange. It only appears to be dirty if you're using ngModel and template-driven forms. FormControl and model-driven forms show up as pristine. Definitely a bug.

@Scipionh
Copy link
Author

Scipionh commented Sep 6, 2016

It actually comes with both ng-pristine and ng-dirty which is really odd. Yes I am using template-driven forms.

@andyrue
Copy link
Contributor

andyrue commented Sep 7, 2016

On initial load, we update the mask and write the value to the model. This is what's marking it as dirty. Seems we need to find a way to mark things as Pristine after initial load but I haven't found a place to successfully do that yet from within the directive.

@msafi msafi changed the title Using a date mask makes the input loading dirty Model starts as "dirty" Sep 7, 2016
@g-serghei
Copy link

I have the same problem

@PerfectPixel
Copy link
Contributor

As I ran into the same problem earlier today, I provided a fix that straightens out a few quirks with the handling of ControlValueAccessor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants