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

Unable to use init-date attribute #2331

Closed
Mitsukurinadae opened this issue Jun 12, 2014 · 21 comments
Closed

Unable to use init-date attribute #2331

Mitsukurinadae opened this issue Jun 12, 2014 · 21 comments

Comments

@Mitsukurinadae
Copy link

Hey all,

I'm unable to get the init-date working as an attribute set for the datepicker, does anyone have any examples I can pull to see where it's working? I was looking at the demo but for whatever reason this commit removed the only reference to the initDate in the Javascript:
#2184

I copied the plunker on the demo page and tried to edit it:
http://plnkr.co/edit/ZGz7rmv09p6SFVVGB9VX?p=preview

I tried sticking it in the datepicker options as initDate: $scope.initDate
and I also tried to just define init-date: initDate on the attributes of the datepicker.

I've browsed through as many issues as I could and Google didn't have an example as the init-date is pretty new.

Thanks for your help!

@mywolrd
Copy link

mywolrd commented Jun 13, 2014

Hello,

I have no idea how to work with datepicker options or datepickerConfig.
For the init-date attribute on a HTML element, you will need to revert the change below. I don't know if it will work for datapicker options or datepickerConfig.

https://github.com/wleelavivat/bootstrap/commit/4fda36a1df69a043b07c8c8f8733144d73f9c79e

The problem is that the init-date attribute in a datepicker element never gets registered in the attribute set of datepickerController, so reverting the change fixes it.

You need to map a Date object to init-date.
You can try it with a string, but for me, passing a date string to init-date gives me one day off result.
init-date ="'2014-07-01'" shows June calendar, not July calendar. Haven't figured out if this is my issue or JavaScript issue.

I tested it on AngularJS 1.2.10, Angular-UI 0.11.0.

@vict-shevchenko
Copy link

Hi, I have the same problem. I have found out, that init-date should be provided only as an datepickerConfig property, because DatepickerController does not see it, if init-date is provided inline.

but this string throws an exception:

this.activeDate = angular.isDefined($attrs.initDate) ? $scope.$parent.$eval($attrs.initDate) : new Date(); 

seems that $scope.$parent.$eval($attrs.initDate) should return a Date obj, but it does not.

$scope.$parent.$eval('new Date()')  //exception 

Can someone please provide an example of using init-date.

@sl45sms
Copy link

sl45sms commented Jun 28, 2014

http://plnkr.co/ijDYzZc9R3Fxw4jTlz46
this works for me

@thomaswinckell
Copy link
Contributor

After trying the code of @sl45sms which worked as he said, I tried to implement it with a popup, and as you can see here http://plnkr.co/yq7OrO8ZecpE7RvwTqvM it doesn't work ! I used the same versions as @sl45sms.

@thomaswinckell
Copy link
Contributor

I have done a pull request to correct that issue : #2438.

@linusnorton
Copy link

I am also experiencing this problem, what can we do to get this merged?

@RichardLitt
Copy link
Contributor

👍

2 similar comments
@am576
Copy link

am576 commented Oct 7, 2014

+1

@gflandre
Copy link

👍

@redben
Copy link

redben commented Nov 2, 2014

Got it working too by passing the datepicker-options { initDate:'$parent.$parent.path.to.variable' }
$parent.$parent because I had a form in my scope (it might be different for you, see #2538 )

Still, I realised the expression was not being watched, which renders it useless in the use case of a from/to pair of datepickers...

@kbaltrinic
Copy link
Contributor

I have been looking into this have made the following determinations which I think satisfy the needed investigation. I would like @chrisirhc to evaluate my conclusions if he has time and if he concurs, I have a fix in place locally that I can submit as a pull request w/o too much effort.

Per the documentation the init-date attribute should work either as its own attribute, or as a value in datepicker-options. As sl45sms demonstrated, init-date works on the datepicker. However it does not work on the datepicker-popup, neither directly nor as part of datepicker-options. Here is why:

In the case of datepicker-options, the problem is that the value is being $evaled twice, once on [line 475](https://github.com/angular-ui/bootstrap/blob/master/src/datepicker/datepicker.js#L475 - 76) and a second time on line 47. This I believe is why redben got things working by using glitches around his 'path.to.variable' and why he needed to prefix it with $parent.$parent. The first $eval removed the glitches effectively set init-date="$parent.$parent.path.to.variable" on datepickerEl (the element representing the popup). Then line 47 again $evaled this at the level of the popup, whose scope is a child of the date-pick which is a child of the page's scope, thus the $parent.$parent.

In the case of applying the init-date attribute directly to the datepicker-popup, the code to handle this is simply missing. It is this case that Thomas W is addressing with pull-request #2438.

Line 47 clearly needs to perform an $eval in order to keep the basic case working which sl45sms demonstrated. Therefore it seems the solution for larger issue it to incorporate into the existing pull request a modification to line 475 to handle things differently for the datepicker-options scenario.

However this only gets us to the point of initially setting the init-date correctly. I believe I now have working code that supports also changing the initdate on the fly to support the from/to case that someone mentioned. The need to support that case is how I got to looking into this to begin with.

Comments?

@jeff-french
Copy link

+1 for setting init-date on the fly.

@kbaltrinic kbaltrinic mentioned this issue Nov 14, 2014
@kbaltrinic
Copy link
Contributor

I have submitted pull request #2972 which I believe addresses all of the issues discussed herein, including that fact that init-date is not watched after initial evaluation.

@felixzapata
Copy link

hi @kbaltrinic, for me your solution works in my project, so I'm afraid that until your pull request will be accepted, I'm gonna to put direct your changes into my file and load the datepicker from local instead of bower.

Sorry :(

Thanks.

@trickpattyFH20
Copy link
Contributor

@felixzapata after you compiled the changes from pull request #2972, how did you implement "init-date"? is it in the dateOptions object like: $scope.dateOptions = { initDate: ''01/14/1997'' }; or was it on the input element with init-date=" '01/14/1997' " or was there some other method/date format that you used?

UPDATE:
I used init-date="minDate" on the input element with minDate being a JS date object and it works perfectly

It would be great if this pull was added to master!!!

@felixzapata
Copy link

for my case, this way:

$scope.dateOptions = {
            minDate: new Date(2014, 11, 1),
            maxDate: new Date(2015, 1, 28),
            initDate: new Date(2015, 0, 9)
        };

<input name="date" datepicker-options="options" date-disabled="disabled(date, mode)" min-date="options.minDate" max-date="options.maxDate" datepicker-popup="dd/MM/yyyy" placeholder="dd/mm/aaaa" is-open="opened" ng-model="date" readonly="readonly" type="text">

@felixzapata
Copy link

not only this pull request @trickpattyFH20 would be great ;) , I would need another pull request that it was sent a few months ago about the navigation.

@michaellopez
Copy link

+1

@dciccale
Copy link

Please accept #2438 made like a hundred years ago!

@rvanbaalen
Copy link
Contributor

Please be just a little more patient. We're actively going through all PRs at the moment.

@wesleycho
Copy link
Contributor

This is truly fixed by 98e2bdf.

@wesleycho wesleycho added this to the 0.13.0 milestone Mar 24, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests