Skip to content

Commit

Permalink
Added option 'allowSameDate'
Browse files Browse the repository at this point in the history
  • Loading branch information
eureka2 committed Oct 18, 2019
1 parent b19c86f commit afbf000
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Add the bootstrap and datepicker css to your page head
```html
<link rel="stylesheet" href="path/to/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="path/to/datepicker.css" type="text/css" />
or
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ab-datepicker@latest/css/datepicker.css" type="text/css" />
```
In case you use bootstrap4 markup (see the markup option), it is necessary to include font 'Font Awesome 5':
```html
Expand All @@ -62,6 +64,9 @@ Place the javascript files to the end of your document:
<script type="text/javascript" src="path/to/jquery.min.js"></script>
<script type="text/javascript" src="path/to/bootstrap.min.js"></script>
<script type="text/javascript" src="path/to/datepicker.min.js"></script>
or
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ab-datepicker@latest"></script>

```

### Basic usage
Expand Down Expand Up @@ -110,6 +115,7 @@ and give some options to the datepicker. See [Configuration options](#configurat

|Option |Description |Default |Example|
|----------------------|-------------------------------------|---------------|-------|
|allowSameDate |In the case of linked dates (start date and end date), this option indicates whether the two dates can be the same. This option is ignored if none of the 'next' or 'previous' option is set.|true|allowSameDate: false|
|buttonLabel |Accessibility label : 'aria-labelledby' attribute for the calendar button|Date.dp_locales.texts.buttonLabel (*)|Cliquez ou appuyez sur la touche Entrée ou la barre d'espace pour ouvrir le calendrier|
|buttonLeft |Place the calendar button to the left of the text field|false|buttonLeft: true|
|buttonTitle |Title attribute for the calendar button|Date.dp_locales.texts.buttonTitle (*)|Sélectionner une date ...|
Expand Down
37 changes: 28 additions & 9 deletions js/datepicker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Accessible Datepicker v2.1.18
* Accessible Datepicker v2.1.19
* Copyright 2015-2019 Eureka2, Jacques Archimède.
* Based on the example of the Open AJAX Alliance Accessibility Tools Task Force : http://www.oaa-accessibility.org/examplep/datepicker1/
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
Expand Down Expand Up @@ -482,7 +482,7 @@
});
}

Datepicker.VERSION = '2.1.18'
Datepicker.VERSION = '2.1.19'

Datepicker.DEFAULTS = {
firstDayOfWeek: Date.dp_locales.firstday_of_week, // Determines the first column of the calendar grid
Expand Down Expand Up @@ -513,6 +513,7 @@
onUpdate: function (value) {},
previous: null,
next: null,
allowSameDate: true,
markup: 'bootstrap3', // bootstrap3 or bootstrap4
theme: 'default',
modal: false,
Expand Down Expand Up @@ -2226,20 +2227,38 @@
Datepicker.prototype.updateLinked = function(date) {
if (this.options.previous !== null && this.options.previous.val() !== '') {
var previousDate = this.options.previous.datepicker('getDate');
if (previousDate > date) {
var previousVal = this.formatDate(date, this.options.previous.datepicker('outputFormat'));
this.options.previous.val(previousVal);
if (this.options.allowSameDate) {
if (previousDate > date) {
var previousVal = this.formatDate(date, this.options.previous.datepicker('outputFormat'));
this.options.previous.val(previousVal);
}
} else {
if (previousDate >= date) {
var previousVal = this.formatDate(new Date(date.getTime() - 60*60*24*1000), this.options.previous.datepicker('outputFormat'));
this.options.previous.val(previousVal);
}
}
}
if (this.options.next !== null && this.options.next.val() !== '') {
var nextDate = this.options.next.datepicker('getDate');
if (nextDate < date) {
var nextVal = this.formatDate(date, this.options.next.datepicker('outputFormat'));
this.options.next.val(nextVal);
if (this.options.allowSameDate) {
if (nextDate < date) {
var nextVal = this.formatDate(date, this.options.next.datepicker('outputFormat'));
this.options.next.val(nextVal);
}
} else {
if (nextDate <= date) {
var nextVal = this.formatDate(new Date(date.getTime() + 60*60*24*1000), this.options.next.datepicker('outputFormat'));
this.options.next.val(nextVal);
}
}
}
if (this.options.next !== null) {
this.options.next.datepicker('min', date);
if (this.options.allowSameDate) {
this.options.next.datepicker('min', date);
} else {
this.options.next.datepicker('min', new Date(date.getTime() + 60*60*24*1000));
}
}
} // end updateLinked()

Expand Down
4 changes: 2 additions & 2 deletions js/datepicker.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eureka2/ab-datepicker",
"version": "2.1.18",
"version": "2.1.19",
"description": "An accessible and bootstrap compatible datepicker",
"main": "js/datepicker.js",
"directories": {
Expand Down

0 comments on commit afbf000

Please sign in to comment.