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

Datepicker - year-range seems to be completely ignored #3338

Closed
rvanbaalen opened this issue Feb 25, 2015 · 12 comments
Closed

Datepicker - year-range seems to be completely ignored #3338

rvanbaalen opened this issue Feb 25, 2015 · 12 comments

Comments

@rvanbaalen
Copy link
Contributor

When I use the year-range attribute on my datepicker-popup directive, it seems to be completly ignored.

I set it to value 9 like this:

year-range="9"

and also tried this:

year-range="'9'"

But both don't work and this is always the result:

screen shot 2015-02-25 at 14 21 09

I would expect the datepicker to show the years in a 3x3 grid (9 total).

I'm using UI Bootstrap 0.12.1 and Angular JS 1.3.13

@karianna
Copy link
Contributor

@antoinepairet Sorry to keep piling these on you, but thought it was worth checking if fixed on HEAD

@rvanbaalen
Copy link
Contributor Author

It has everything to do with this fancy line of code (which is very hard to read):

self[key] = angular.isDefined($attrs[key]) ? (index < 8 ? $interpolate($attrs[key])($scope.$parent) : $scope.$parent.$eval($attrs[key])) : datepickerConfig[key];

$attrs.yearRange is not defined. Therefore, the default datepickerConfig option is selected. Which is 20. It seems, based on this piece of code, that the yearRange never worked to start with. It probably works when you set it as a global option but not when defined as an attribute like I did.

@rvanbaalen
Copy link
Contributor Author

I've rewritten that oneliner to a more debuggable block:

if(angular.isDefined($attrs[key])) {
  if (index < 8) {
      var val = $interpolate($attrs[key])($scope.$parent);
      self[key] = val;
  } else {
      var val = $scope.$parent.$eval($attrs[key]);
      self[key] = val;
  }
} else {
  self[key] = datepickerConfig[key];
}

Now I'm wondering -- why loop through injected $attrs service? That service does not seem to be picking up the attributes set on my element (such as year-range). It has all attributes defined from the actual template instead of my initial element where I define the configuration attributes on.

@rvanbaalen
Copy link
Contributor Author

Well for now I've worked around this issue by setting yearRange as a property of my datepicker-options object. I still think this should be fixed but due to the complexity of the DatepickerController I haven't been able to create a solid fix and thus a PR.

Not working

<input
        type="text"
        class="form-control input-sm"
        placeholder="{{ 'LABEL.PLEASE_CHOOSE' | translate }}"
        id="dob"
        name="dob"
        ng-model-options="formModelOptions"
        ng-model="dob"
        max-date="datepickerEighteen"
        datepicker-mode="'year'"
        datepicker-popup="dd-MM-yyyy"
        year-range="9"
        datepicker-options="dobOptions"
        is-open="dobOpened"
        required
        readonly="readonly" />

Workaround

<input
        type="text"
        class="form-control input-sm"
        id="dob"
        name="dob"
        oh-validate-model-state
        ng-model-options="formModelOptions"
        ng-model="dob"
        max-date="datepickerEighteen"
        datepicker-mode="'year'"
        datepicker-popup="dd-MM-yyyy"
        year-range="9"
        datepicker-options="dobOptions"
        is-open="dobOpened"
        required
        readonly="readonly" />
$scope.dobOptions = {
    yearRange: 9
};

@karianna karianna modified the milestones: 0.13.0, 0.13.x Feb 27, 2015
@rvanbaalen
Copy link
Contributor Author

@karianna That looks promising.. there won't be a fix any time soon? 😉

@karianna
Copy link
Contributor

@antoinepairet Is our resident datepicker maintainer (at present) - we'll be looking at all of the related PRs over the coming weeks (it's going to take some time) :-)

@rvanbaalen
Copy link
Contributor Author

@karianna @antoinepairet If you're able to shortly explain to what your process is to check these related PRs I might be able to help out. I wouldn't mind being a contributor for the datepicker module. I'm using it a lot in projects are able to debug issues / implement fixes.

For now I'll stick to PRs but you guys already have a lot of these pending.

@karianna
Copy link
Contributor

@rvanbaalen If you'd like to become a maintainer then you'd be more than welcome. Please join the gitter where we discuss merges etc. We'll have a meeting to triage PRs next week as well IIRC

@rvanbaalen
Copy link
Contributor Author

I would definitely be interested in becoming a contributor @karianna. I did find the gitter indeed. Just need to catch up with everything going on there.

@karianna
Copy link
Contributor

Can't see why this is a angular 1.3 support issue - moving to 0.13.x

@rvanbaalen
Copy link
Contributor Author

The 0.13 milestone was added before we had a meeting about the contents of 0.13 😉

@wesleycho wesleycho modified the milestones: 0.14.2, 0.14.1, 0.14.3 Oct 11, 2015
@wesleycho wesleycho modified the milestones: 0.14.3, 1.0.0 Oct 23, 2015
@davious
Copy link
Contributor

davious commented Nov 7, 2015

Would like to help, but I'm confused about what's wanted here.
Would we like the popup directive to pass through the year-range attribute to the datepicker?

davious added a commit to davious/angular-ui-bootstrap that referenced this issue Nov 9, 2015
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Nov 10, 2015
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Nov 10, 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.

6 participants