3

I am using the Datepicket that is part of the AngularJS ui-bootstrap module. I'm following the tutorial / example given (see http://angular-ui.github.io/bootstrap/#/datepicker) but when trying to prevent users from selecting dates earlier than today or greater than 3 months from today doesn't seem to be working correctly as these are still clickable.

This is the datepicker in my view... I've written the ng-model, min-date & max-date values to the interface to make sure these are not null)

<datepicker ng-model="dt" min-date="minDate" max-date="maxDate" show-weeks="false"></datepicker>
dt = {{ dt }}
minDate = {{ minDate }}
maxDate = {{ maxDate }}

The values are being returned....

dt = "2014-04-30T15:31:46.746Z" 
minDate = "2014-05-27T15:31:46.746Z"
maxDate = "2014-08-27T15:31:46.751Z"

this is my controller code... most of it taken from the example provided on the ui-bootstrap site

$scope.today = function() {
  $scope.dt = new Date();
};
$scope.today();

$scope.toggleMin = function() {
  $scope.minDate = $scope.minDate ? null : new Date();
};
$scope.toggleMin();

$scope.maxDate  = new Date(new Date().setMonth(new Date().getMonth()+3));

Can anyone see what I'm doing wrong? I can't see what typo or mistake I have made? I am using Chrome 34.0.1847.137 on OS X 10.9.2 so browser compatibility shouldn't be an issue.

1

5 Answers 5

11

Simply use min and max attribute instead of min-date and max-date respectively in datepicker tag.

<input min="p.minStartDate" max="p.maxStartDate" ng-model="p.startDate" datepicker-popup="{{'dd-MM-yyyy'}}"  datepicker-options="p.dateOptions"/>
Sign up to request clarification or add additional context in comments.

4 Comments

Not sure why this is not in the doc. Thanks a lot :)
So baffled by this... min-date works just dandy in the demo and this plunker but in my app, using the same exact angular & ui-bootstrap versions, I cannot get min-date to work, but min works fine. Good enough for now, but if anyone has insight, please lemme know.
@brandonjp: Maybe this isn't in the datepicker documentation, because this isn't a datepicker specific validator but a "normal" angular validaor. See docs.angularjs.org/guide/forms, they mention min and max.
min and max validate the input field. min-date and max-date control the datepicker and disable dates beyond that range.
6

What version of Angular Bootstrap are you using? I noticed I had to upgrade to 0.11.0 to get min and max date to work. In 0.10.0, min and max date did not work for me. I had to use date-disabled instead.

2 Comments

We have a winner! Thanks for the answer, an upgrade has solved this issue!
Can you show me your implementation of data-disabled Imyers? Having the same issue.
3
<input type="text" datepicker-popup="{{format}}" 
                            ng-model="dt" is-open="opened" 
                            min="'2014-09-09'" max="'2015-06-22'"
                            datepicker-options="dateOptions" 
                            date-disabled="disabled(date, mode)" 
                            ng-required="true" 
                            close-text="Close" />

It work for me with the angular-1.2.8 version

Comments

1

I couldn't get the max or max-date attributes to work.

Instead, I found that I had to configure the datepicker-options property on the control. Reference here.

Template

<input type="text" class="form-control" uib-datepicker-popup="d/M/yyyy" ng-model="ctrl.calendarControl.selectedDate" datepicker-options="ctrl.calendarControl.dateOptions" />

Controller

self.calendarControl = {
    dateOptions: {
        maxDate: new Date()
    }
};

Comments

-5
    $(function () {
        $("[id$=txtpaymentdate]").datepicker({
            showOn: 'button',
            buttonImageOnly: true,
            format: "dd/mm/yyyy",

            todayBtn: "linked",
            language: "ru",
            autoclose: true

        });
    });

1 Comment

Welcome to Stackoverflow. As we can see the question has been tagged with angular js.

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.