Ensures that 2 way binding occurs with the input field so that the outer generate alias updates the inner value and vice versa

This commit is contained in:
Shannon
2016-01-12 13:21:10 +01:00
parent c819dabfc0
commit 74d8068de1
2 changed files with 10 additions and 4 deletions

View File

@@ -17,12 +17,18 @@
// this ensures that the normal flow (i.e. a user editing the text box) occurs so that
// the parsers, validators and viewchangelisteners execute
scope.$watch("ngModel", function (newValue, oldValue) {
if (newValue !== oldValue) {
if (newValue !== oldValue) {
//Hack: in order for the pipeline to execute for setViewValue, the underlying $modelValue cannot
// match the value being set with the newValue, so we'll se it to undefined first.
// We could avoid this hack by setting the ngModel of the lockedField input field to a custom
// scope object, but that would mean we'd have to watch that value too in order to set the outer
// ngModelCtrl.$modelValue. It's seems like less overhead to just do this and not have 2x watches.
scope.lockedFieldForm.lockedField.$modelValue = undefined;
scope.lockedFieldForm.lockedField.$setViewValue(newValue);
scope.lockedFieldForm.lockedField.$render();
}
});
var input = el.find('.umb-locked-field__input');
function activate() {

View File

@@ -13,7 +13,7 @@
<input type="text"
class="umb-locked-field__input"
name="lockedField"
ng-model="inputModel"
ng-model="ngModel"
ng-disabled="locked"
ng-class="{'-unlocked': !locked}"
placeholder="{{placeholderText}}"
@@ -21,7 +21,7 @@
umb-auto-resize
required
val-server-field="{{serverValidationField}}"
title="{{inputModel}}" />
title="{{ngModel}}" />
</div>