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

fix(datepicker): fix popup to work with ng-model-options:updateOn='default' #5529

Closed
wants to merge 1 commit into from

Conversation

B8li
Copy link
Contributor

@B8li B8li commented Feb 24, 2016

When using datepicker with popup and ng-model-options="{ updateOn: 'default'}", value can not be set via popup.

Plnkr with the problem(and hacky solution):
http://plnkr.co/edit/4LLbxCkWBzoPwJuOAbye?p=preview

This PR fixes this problem and selection(update model) via datepicker popup is possible again.

Use case for this scenario

Often we define ng-model-options={ updateOn: 'blur'} for multiple wrapped elements(e.g form).
For datepicker that is inside that element(form) usually doesn't make sense to update model value on blur, so we need to add ng-model-options to the datepicker element.

Technical information

AngularJS directive ng-model-options parses the given expression and object that is set to ngModel.$options is different then the object in expression. Here is ngModelOptions directives from angularJS code that changes this:

var ngModelOptionsDirective = function() {
  return {
    restrict: 'A',
    controller: ['$scope', '$attrs', function($scope, $attrs) {
      var that = this;
      this.$options = copy($scope.$eval($attrs.ngModelOptions));
      // Allow adding/overriding bound events
      if (isDefined(this.$options.updateOn)) {
        this.$options.updateOnDefault = false;
        // extract "default" pseudo-event from list of events that can trigger a model update
        this.$options.updateOn = trim(this.$options.updateOn.replace(DEFAULT_REGEXP, function() {
          that.$options.updateOnDefault = true;
          return ' ';
        }));
      } else {
        this.$options.updateOnDefault = true;
      }
    }]
  };

So when we use ngModelOptions.$options value to compile uib-datepicker-popup-wrap , we lose updateOn property and ngModel can not be updated using the pop up.

…updateOn='default'

 - Add 'updateOn' property to datepicker popup ngModelOptions. AngularJS modifies ngModelOptions object when 'updateOn: default' is passed.
@wesleycho wesleycho added this to the 1.2.0 milestone Feb 24, 2016
@wesleycho
Copy link
Contributor

LGTM - thanks for this subtle catch...don't like how Angular seems to handle this.

@wesleycho wesleycho closed this in 47e412e Feb 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants