Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

cannot disable dates in datepicker #1432

Closed
longilineo opened this issue Jan 14, 2015 · 5 comments
Closed

cannot disable dates in datepicker #1432

longilineo opened this issue Jan 14, 2015 · 5 comments

Comments

@longilineo
Copy link

I'm trying to disable all italian festivities in angularstrap datepicker but data-disabled-dates attributes is ignored

Here is how I'm generating array with festivities:

function ListaFestivita(anni){
  var feste = [];
  for(x in anni){
    for(y in festefisse){
      feste.push({start: new Date(anni[x], festefisse[y].m-1, festefisse[y].g), end: new Date(anni[x], festefisse[y].m-1, festefisse[y].g)});
    }
  }
  return feste;
}

var festefisse = [
  {g: 1, m: 1, n: "capodanno"}, {g: 6, m: 1, n: "epifania"}, 
  {g: 25, m: 4, n: "liberazione"}, 
  {g: 1, m: 5, n: "lavoratori"}, 
  {g: 2, m: 6, n: "repubblica"}, 
  {g: 15, m: 8, n: "assunzione"}, 
  {g: 1, m:11, n: "santi"}, 
  {g: 8, m: 12, n: "immacolata"},
  {g: 25, m: 12, n: "natale"},
  {g: 26, m: 12, n: "santo stefano"}
];

Inside a controller I've:

$scope.festivita = new ListaFestivita([2015,2016]); 

In html:

<input class="form-control" type="text" name="ritiro" placeholder="gg-mm-aaaa" data-ng-model="ritiro" id="ritiro" 
             bs-datepicker="true" data-date-format="dd-MM-yyyy"
             required="true" 
             data-days-of-week-disabled='06'
             data-start-date="{{startDate}}"
             data-min-date="{{minDate}}" 
             data-max-date="{{maxDate}}" 
             data-disabled-dates="{{festivita}}" />
@longilineo
Copy link
Author

I'm not sure if it's the best (or the worst) way, but by changing angular-strap.js "views.isDisabled" seems to work:

          // Disabled because of disabled date range.
          if (options.disabledDateRanges) {

            for (var i = 0; i < options.disabledDateRanges.length; i++) {
              var startRange = new Date(options.disabledDateRanges[i].start).getTime();
              var endRange = new Date(options.disabledDateRanges[i].end).getTime();
              if (time >= startRange && time <= endRange) {
                return true;
              }
            }
          }

@KaneConnor
Copy link

Hi all,
I've same problem here. I'm using:
$scope.nodates={ start: new Date(1999, 11, 24), end: new Date(2010, 11, 25) };
but these dates remain selectable.
The longilineo solution doesn't work for me.
Any suggestion?

@vmlf01
Copy link
Collaborator

vmlf01 commented Jun 3, 2015

For @longilineo case, I added the disabled-dates attribute with the scope variable without the interpolation (no {{ }}).
In @KaneConnor case, the disabled-dates actually takes an array of objects, so just putting the object inside an array did it for me.

Check this plunker for example:
http://plnkr.co/edit/BVsm4OaxF6vNT3oy8lQc?p=preview

@vmlf01 vmlf01 closed this as completed Jun 3, 2015
@vmlf01
Copy link
Collaborator

vmlf01 commented Jun 3, 2015

If you come across more issues, feel free to re-open.

@lock
Copy link

lock bot commented Jan 26, 2019

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.

@lock lock bot added the outdated label Jan 26, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 26, 2019
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

3 participants