Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Typeahead does not support ng-model-options="{getterSetter: true}" #3823

Closed
pkarikh opened this issue Jun 15, 2015 · 3 comments
Closed

Typeahead does not support ng-model-options="{getterSetter: true}" #3823

pkarikh opened this issue Jun 15, 2015 · 3 comments

Comments

@pkarikh
Copy link

pkarikh commented Jun 15, 2015

AngularJS: v1.3.
ui-bootstrap: v 0.13.

Looks like when I set ng-model-options="{getterSetter: true}" typeahead for some reasons replaces getter/setter method with selected value.

Here the plankr: http://plnkr.co/edit/a3Ld9eVmysrt8RsyzbhX?p=preview
Steps:
0) Note from the sources that suggestions.value is a getter/setter.

  1. Type "one" or "two"
  2. Note that suggestions.value is not a function any more. It is a choosen value from typeahead suggestion.
@pkarikh
Copy link
Author

pkarikh commented Jun 17, 2015

Looks like this fix works.

If we replace this line: var $setModelValue = $parse(attrs.ngModel).assign;
with this code:

 var $setModelValue = (function() {
    var options = $parse(attrs.ngModelOptions)(),
      parsedNgModel = $parse(attrs.ngModel),
      parsedNgModelAssign = $parse(attrs.ngModel).assign,
      ngModelSet;
      if (options && options.getterSetter) {
      var invokeModelGetter = $parse(attrs.ngModel + '()'),
        invokeModelSetter = $parse(attrs.ngModel + '($$$p)');

      ngModelSet = function($scope, newValue) {
        if (angular.isFunction(parsedNgModel($scope))) {
          invokeModelSetter($scope, {
            $$$p: newValue
          });
        } else {
          parsedNgModelAssign($scope, modelCtrl.$modelValue);
        }
      };
    }

    return ngModelSet || parsedNgModelAssign;
  })();

everything works fine, all tests pass and now typeahead knows how to work with ngModelOptions={getterSetter: true}.
Here the commit: pkarikh@6baf354
And here the plnkr: http://plnkr.co/edit/j3ZQS0gAraVxwmMOWL0l?p=preview

@wesleycho
Copy link
Contributor

@pkarikh: I believe I have a better fix in #3865, take a look at it and let me know if it satisfies your needs whenever you get the chance.

@pkarikh
Copy link
Author

pkarikh commented Jun 29, 2015

@wesleycho your fix works for me. Thank you! Your approach is much more clearer.

@wesleycho wesleycho modified the milestones: 0.13.1 (npm), 0.13.2 (Performance) Jul 23, 2015
openstack-gerrit pushed a commit to openstack-archive/merlin that referenced this issue Jul 31, 2015
This patch adds patched version of angular-ui/bootstrap lib.
We need to patch it because of typeahead - one of bootstrap
components. This component does not support
ngModelOptions="{getterSetter: true}", which we need for
barricade.js integration.
Angular-ui/bootstrap upstream bug:
angular-ui/bootstrap#3823
Until this bug is not fixed in upstream version,
we need to use this patched version of library.

Change-Id: I30a5d52d3a638fa2d7ca110d8824682c3d205611
@wesleycho wesleycho modified the milestones: 0.13.2 (1.4 support), 0.13.3 (Performance) Aug 2, 2015
@wesleycho wesleycho modified the milestones: 0.13.3 (Fixes), 0.13.4 (Performance) Aug 9, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants