-
Notifications
You must be signed in to change notification settings - Fork 291
ng-model-options debounce prevents default value from being displayed #127
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
Conversation
The Angular docs say: .. why do I then need this. Can you point me on a behavior where not calling this function causes some unwanted effect? |
This is the quoted functionality of your ngModel directive:
This functionality no longer works if you have Although is there a particular reason why you're not using |
I've tested this against 0.7.10 and it works for angular 1.3+ when using the new ng-model-options debounce on an input. If you test the second commit (which uses 1.2.3), then the name 'james' should appear as the defaultValue in the 'first name' input, but it doesn't. If you check your console you'll see that 'james' is output and if you inspect the ngModel instance, although the $viewValue is initially set to 'james', it then appears to be set back to undefined. Calling $commitViewValue fixes this issue as this method was introduced on ngModelController in 1.3 to do exactly that. Force the view value to the model when debounce is being used. Using $modelValue to set the default instead (as i'd suggested earlier) doesn't work in versions before 1.3. |
@jrief You can ignore everything here except for the final commit. This is my preferred fix for this issue, as it simply sets the default value directly onto the scope model, which For an alternate fix that's closer to your original, but which tests for 1.3 features and uses the |
Hi @jamesbrobb I'm trying to go through old issues and PR to clean this repo a bit. Do you know if this PR is still needed? Can you point me a failing behavior right that this PR fixes? You said there is an alternative solution for that problem? I'm eager to merge #152 as well 'cause I'm facing this issue right now... |
Hi @adrienbrunet , i'm afraid i'm not as it's been a while since i submitted this PR (and the rest) and i've not used django-angular since, so i have no idea what's been changed. It's worth looking at #160, as i'd found quite a few issues with the way the JS has been written and give a fairly extensive explanation of the changes i'd made. |
@jrief I'm closing this one. If we need to merge something, it should be from PR #152 |
In the
ngModel
directiverestoreInputField
method you need to callmodelCtrl.$commitViewValue()
aftermodelCtrl.$setViewValue()
to ensure that the default value is displayed