9

I am trying to use the angular UI strap datepicker. How to select more than one date from the datepicker and return the value as an array.

http://mgcrea.github.io/angular-strap/#/datepicker

5
  • I dont see the reason, its not multiple file selection. Can you explain the reason, example. I really never seen something like. DatePIcker supports one date only, and fills textfield Commented May 29, 2013 at 19:39
  • I think he means something like when booking a vacation on an airline. You can select multiple days. Angular-ui's datePicker does not support this though so @Abre will have to create their own directive. Commented May 29, 2013 at 19:53
  • yes, something like this. multidatespickr.sourceforge.net Commented May 30, 2013 at 4:09
  • If that is what is being asked, then take a look at this Commented Feb 17, 2014 at 10:48
  • I wrote a module that extends UI Bootstrap's Datepicker to select multiple dates. github.com/spongessuck/gm.datepickerMultiSelect Commented Nov 14, 2014 at 19:01

2 Answers 2

3

You can use gm.datepickerMultiSelect directive, that wraps around ui-bootstrap datepicker directive, adding multi-select feature.

<div ng-controller='AppCtrl'>
    <datepicker ng-model='activeDate' multi-select='selectedDates'></datepicker>
</div>


var myApp = angular.module('myApp',['gm.datepickerMultiSelect']);

function AppCtrl($scope) {
    $scope.activeDate;

    //THIS IS WHERE YOU CAN INITIALIZE VALUES
    $scope.selectedDates = [new Date().setHours(0, 0, 0, 0), new Date(2015, 2, 20).setHours(0, 0, 0, 0), new Date(2015, 2, 10).setHours(0, 0, 0, 0), new Date(2015, 2, 15).setHours(0, 0, 0, 0)];

    $scope.removeFromSelected = function (dt) {
        $scope.selectedDates.splice($scope.selectedDates.indexOf(dt), 1);
    }
}

There's an article on this on my blog http://irhadbabic.com/?p=351 Also, here's working JSFiddle that you can use http://jsfiddle.net/prdkvp7u/4/

Sign up to request clarification or add additional context in comments.

Comments

2

The directive that you're working with doesn't support the multi-datepicker that you want. You can always go for something like Bootstrap Datepicker and not necessarily stick with an Angular directive.

Your option is fairly limited in this regard unless you customize the directive the way you want it to behave.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.