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

Form dirty with when mask loads with divisors #30

Closed
candreoliveira opened this issue Jun 4, 2015 · 4 comments
Closed

Form dirty with when mask loads with divisors #30

candreoliveira opened this issue Jun 4, 2015 · 4 comments

Comments

@candreoliveira
Copy link
Owner

http://plnkr.co/edit/Ahlzf0TXhcnNtlM45OQA?p=preview

@ldeavila
Copy link
Contributor

+1

@ldeavila
Copy link
Contributor

Tried updating the controller inside the post function but that does not update the parent form controller. Found this: http://stackoverflow.com/questions/19320062/accessing-parent-directives-controller-recursively-in-angularjs. It lets me update the parent form and set it to pristine but i'm not sure where to place such code so that the form is pristine only when the directive first renders the form. Thoughts?

@mvarshavsky
Copy link

Okay, my thinking was along similar lines to what @ldeavila is suggesting. Tag on some variable that would track if we're doing the initial $setViewValue call or not. If so, I was going to set pristine to true, then climb up to the form $element.context.form and set it to pristine as well. Obviously a hack, but whatever. Then I stumbled across this: zensh/ui-autocomplete#6

So the pertinent snippet, inside parseViewValue, where we "Update view and model values":

  controller.$pristine = false
  controller.$setViewValue(angular.copy(viewValueWithDivisors), 'input');
  controller.$pristine = true

It appears to be working for me. Now I'm really bothered by not understanding why it is working. Why doesn't this code dirty up the form on initial load, but consecutive keyup's, etc also have the desired behavior of making it dirty? I get that ngModelController.$commitViewValue only sets dirty when it is pristine... but what ever sets it dirty then?

@candreoliveira, what are your thoughts on this approach?

@belluccifranco
Copy link

+1

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

No branches or pull requests

4 participants