I have an angular uib datepicker that works fine when selecting dates, but now I need something else from it.
I would like to be able to call a function when the user navigates through the month/year menu.
Until now, the datepicker only reacts when a day is selected (the ng-model changes, ng-change is called etc etc). I want to call a function when the user uses the top menu and he/she didn't click on a day yet. Just going from one month to another, either with the arrows or with the month/year selector, I would need to call a function.
Is there any way to do it? I can't figure it out.
Appreciate it.
We finally figured it out.
Using a decorator (that we learned from here Angular Bootstrap Datepicker change month event) you can throw a function when the month or the year is changed in a datepicker.
Related
I've mixed a couple of examples (CustomView, Moment JS localization) in order to create a view that only shows each Wednesday and Thursday. However, the events are not displayed.
The events are transferred from the parent to the child component (including the Calendar component). However, simply hardcoding events also does not work.
I feel like it's a problem within the custom view, but I cannot find what exactly.
See codesandbox.
The first thing I notice, looking at your codesandbox, is that you forgot to include the stylesheet. This is mentioned in the Getting Started section of the documentation. Your min and max props are being passed moment objects, rather than true js Date objects. And the hardcoded event date you included wasn't in the displayed date range.
I've made a date picker directive that uses a single date picker from the improvely datepicker library. It has two input tags and an OK button.
Date Picker Library
Single Date Picker Example
If I change the value of the input field via the keyboard the models get the desired value and calls to the server take place as expected. The problem arises when I use the date picker. The value of the model does not change. It still has the same value that I set via the keyboard.
But if I run document.getElementById('frompicker').value using the console it shows me the right date that I set using the datepicker.
If I don't set any value form the keyboard and only use the datepicker drop down, the values of the models are undefined.
I've tried a few solutions offered for Angular Boostrap UI Datepicker and Angular UI Datepicker. None of them work.
Edit after a comment
Code can be found here - https://plnkr.co/edit/HzkYzUajGlsZq5KhUwsx
Any help is greatly appreciated :)
You should sync scope after datepicker change via
$scope.$apply();
or
$scope.$evalAsync();
seems it 'apply.daterangepicker' event for your datepicker
I tried all the methods mentioned in different answers. My colleagues told that it's a bad idea to use $scope.$evalAsync() or $scope.$apply() unnecessarily. Our code base does not use digest, compile and the likes. So that was causing a hindrance.
I finally decided to detect the date change event as suggested by Valery Kozlov (the accepted answer) and manually changing the model.
I accessed the date like this.
$('#frompicker').val(); // can be done without jQuery as well
Changed the model using this.
// use Angular's $on to make things consistent if needed
$('#frompicker').on('apply.daterangepicker', function(ev, picker) {
scope.vm.from_date = $('#frompicker').val();
});
Does anyone have a solution to updating angular ui's disabled dates from a server response?
https://github.com/angular-ui/bootstrap/issues/779
You should create another directive that will require datepicker's controller. From your
directive you should call the refreshView of the datepicker to reevalute the disabled dastes.
Does anyone have example code for that?
I'm trying to use angular ui datepicker so that the disabled dates are read from a server response. I change the datepicker's min date to force it to refresh.
I saw another stackoverflow page where the user had it refresh, but it relied on the datepicker calendar being clicked. Another one used set the date min attribute as the value of another field.
For me, I have a completely separate field from the date picker. When changed, it sends an http request to the server, and on a successful response the available dates are updated.
The only problem with changing the min date to force a refresh is that sometime's there same but with different dates to disable. I'm looking into changing a datepicker option I do not use to a random value to force a refresh.
Does anyone have a better way? I saw cross controller communication via a service, but this is a different module. I also saw a github issue where the datepicker controller can be
I've found a simple solution to this problem using a decorator: https://gist.github.com/cgmartin/3daa01f910601ced9cd3
Then, you only need to call $scope.$broadcast('refreshDatepickers') to refresh the datepickers.
IMPORTANT: For more recent ui-bootstrap datepicker library, you may need to replace 'datepickerDirective' with 'uibDatepickerDirective' if you are using datepicker with uib-datepicker element or attribute.
The angular bootstrap datepicker has datepicker-options
This user listed the solution: https://github.com/angular-ui/bootstrap/issues/2189#issuecomment-225685104
bogdandrumen commented on Jun 13
Use datepicker-options="{minDate: yourScopeMinDate}"
which worked for me. I have two pickers, the second picker cannot be greater than the first one so if the first picker changes, the second picker's max date also changes.
I am using Angular UI Calendar to display some events on the calendar. Whenever the calendar is loaded for the 1st time, the events extend to next date or shown on some other Date.
However when I change the View(Day/Week) and come back again to Month view, then events are displayed fine. Similarly, after changing month and coming back again to the current month , the events are displayed correctly.
Also, I've noticed that the calendar height also increases by 95px after changing the view(when displayed correctly).
Why is this occuring. How can I render events correctly for 1st time?
The problem was with CSS. Solved it.
I can't seem to get the inlined calendar button associated with the DatePicker to work using ng-repeat on two DatePickers. They both work when I instantiate the DatePickers separately, but I wanted to try and use ng-repeat. I want to be able to associate the two DatePicker fields so when you fill out "Date From" it will set the min date of "Date To". I put an example together of the buttons not working or calling open() properly, not sure how to do the rest yet, still very new to AngularJS.
http://plnkr.co/edit/EPg0fmZN7YdVsvhiRgBa
Thanks