mgcrea / angular-strap

AngularJS 1.2+ native directives for Bootstrap 3.
mgcrea.github.io/angular-strap
MIT License
5.73k stars 1.38k forks source link

Datepicker - can't set tomorrow date as default #2215

Closed claubanu closed 7 years ago

claubanu commented 7 years ago

Hi there! My issue: the user must select two dates, the beginning and the end of the interval. By default, first option is today and the second option (the end of the interval) should be tomorrow (by default, for a better user experience). Can somebody, please, help me set tomorrow as default value for the second date option? Thanks in advance!

DaleWebb commented 7 years ago

What happens when you try to set tomorrow as the default value?

claubanu commented 7 years ago

Hi Dale,

In view (html) I have two date inputs with bs-datepicker directive putting first date on ng-model="firstDate" and second date on ng-model="secondDate".

In the controller I set the datepicker and date variables as following:

angular.module('myApp') .config(function($datepickerProvider) { angular.extend($datepickerProvider.defaults, { dateFormat: 'dd/MM/yyyy', startWeek: 1 }); });

$scope.firstDate = new Date();

And for the secondDate I've tryed different combinations like: var today = new Date(); $scope.secondDate = new Date(today+1); or $scope.secondDate = new Date($scope.firstDate+1);

The idea is that I want firstDate to be today and secondDate to be tomorrow by default.

Any advice is welcome! Thank you very much.

DaleWebb commented 7 years ago

If you create a plunkr that recreates the problem, we can start from there :)

claubanu commented 7 years ago

Well, first time with plunkr...Maybe you can understand why isn't working the bs-datepicker directive plus the desired behaviour from those two date inputs,. https://plnkr.co/edit/TasV5U3jPZXBwjkDBZ9p?p=preview

DaleWebb commented 7 years ago

I modified the body of the controller to this:

$scope.data1 = new Date();
$scope.data2 = new Date();
$scope.data2.setDate($scope.data1.getDate() + 1);

This worked.

claubanu commented 7 years ago

Also worked for me. Thank you very much!

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.