Skip to content

Commit

Permalink
error.dp event and minor fixes
Browse files Browse the repository at this point in the history
fixes for #39, #40, #41
  • Loading branch information
Eonasdan committed Oct 24, 2013
1 parent 7a6859c commit 5a349e4
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 23 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
##Using [Moment.js](https://github.com/moment/moment)
Version 2 now requires Momentjs. Version 1 can still be found [here](https://github.com/Eonasdan/bootstrap-datetimepicker/tree/version1). Version 2 has better support for date formats and mutilanguage. See [documentation](http://eonasdan.github.io/bootstrap-datetimepicker/) for examples.

####New feature (2.0.1)!
* New event `error.dp` fires when plugin cannot parse date or when increase/descreasing hours/minutes to a disabled date. See [Example#7](http://eonasdan.github.io/bootstrap-datetimepicker/#example7)
* Minor fixes

####New feature (2.0.0)!
* `disabledDates` is now an option to set the disabled dates. It accepts date objects like `new Date("November 12, 2013 00:00:00")` and `12/25/2013' and `moment` date objects. See [Example#7](http://eonasdan.github.io/bootstrap-datetimepicker/#example7) for usage.
* Events are easier to use; see [Example#8](http://eonasdan.github.io/bootstrap-datetimepicker/#example8)

###Removed features
* pickSeconds
* pick12HourFormat
* maskInput

####New feature (2.0.0)!
* `disabledDates` is now an option to set the disabled dates. It accepts date objects like `new Date("November 12, 2013 00:00:00")` and `12/25/2013' and `moment` date objects. See [Example#7](http://eonasdan.github.io/bootstrap-datetimepicker/#example7) for usage.
* Events are easier to use; see [Example#8](http://eonasdan.github.io/bootstrap-datetimepicker/#example8)

Documentation is [here](http://eonasdan.github.io/bootstrap-datetimepicker/) with examples and usage.
4 changes: 2 additions & 2 deletions build/js/bootstrap-datetimepicker.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions component.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "bootstrap-datetimepicker",
"version": "2.0.0",
"version": "2.0.1",
"main": ["build/css/bootstrap-datetimepicker.min.css","build/js/bootstrap-datetimepicker.min.js"],
"dependencies": {
"jquery" : ">=1.8.3",
"bootstrap" : ">=3.0",
"moment": "2.3.1"
"moment": ">=2.3.1"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bootstrap-datetimepicker",
"version": "2.0.0",
"version": "2.0.1",
"repository": {
"type": "git",
"url": "git://github.com/eonasdan/bootstrap-datetimepicker.git"
Expand Down
73 changes: 58 additions & 15 deletions src/js/bootstrap-datetimepicker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
/**
* version 2.0.1
* @license
* =========================================================
* bootstrap-datetimepicker.js
* http://www.eyecon.ro/bootstrap-datepicker
* =========================================================
* Copyright 2012 Stefan Petre
*
* Contributions:
* - Andrew Rowls
* - Thiago de Arruda
* - updated for Bootstrap v3 by Jonathan Peterson @Eonasdan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================================================
*/
;(function ($) {

var dpgId = 0,
Expand Down Expand Up @@ -161,6 +188,13 @@
date: picker.getDate()
});
},

notifyError = function(date){
picker.element.trigger({
type: 'error.dp',
date: date
});
},

update = function (newDate) {
moment.lang(picker.options.language);
Expand All @@ -171,7 +205,7 @@
} else {
dateStr = picker.element.find('input').val();
}
if (dateStr) picker.date = moment(dateStr);
if (dateStr) picker.date = moment(dateStr, picker.format);
if (!picker.date) picker.date = moment();
}
picker.viewDate = moment(picker.date).startOf("month");
Expand All @@ -181,17 +215,18 @@

fillDow = function () {
moment.lang(picker.options.language);
var dowCnt = moment().weekday(0).weekday(), html = $('<tr>');
var dowCnt = moment().weekday(0).weekday(), html = $('<tr>'), weekdaysMin = moment.weekdaysMin();
while (dowCnt < moment().weekday(0).weekday() + 7) {
html.append('<th class="dow">' + moment()._lang._weekdaysMin[(dowCnt++) % 7] + '</th>');
html.append('<th class="dow">' + weekdaysMin[(dowCnt++) % 7] + '</th>');
}
picker.widget.find('.datepicker-days thead').append(html);
},

fillMonths = function () {
var html = '', i = 0;
while (i < 12) {
html += '<span class="month">' + moment()._lang._monthsShort[i++] + '</span>';
moment.lang(picker.options.language);
var html = '', i = 0, monthsShort = moment.monthsShort();
while (i < 12) {
html += '<span class="month">' + monthsShort[i++] + '</span>';
}
picker.widget.find('.datepicker-months td').append(html);
},
Expand All @@ -204,14 +239,14 @@
startMonth = picker.options.startDate.month(),
endYear = picker.options.endDate.year(),
endMonth = picker.options.endDate.month(),
prevMonth, nextMonth, html = [], row, clsName, i, days, yearCont, currentYear;
prevMonth, nextMonth, html = [], row, clsName, i, days, yearCont, currentYear, months = moment.months();

picker.widget.find('.datepicker-days').find('.disabled').removeClass('disabled');
picker.widget.find('.datepicker-months').find('.disabled').removeClass('disabled');
picker.widget.find('.datepicker-years').find('.disabled').removeClass('disabled');

picker.widget.find('.datepicker-days th:eq(1)').text(
moment()._lang._months[month] + ' ' + year);
months[month] + ' ' + year);

prevMonth = moment(picker.viewDate).subtract("months", 1);
days = prevMonth.daysInMonth();
Expand Down Expand Up @@ -424,7 +459,7 @@
},

decrementMinutes: function () {
checkDate("subtract","hours");
checkDate("subtract","minutes");
},

togglePeriod: function () {
Expand Down Expand Up @@ -486,8 +521,13 @@
set();
} else if (val && val.trim()) {
picker.setValue(picker.date.getTime());
if (picker.date.isValid) set();
else input.val('');
if (picker.date.isValid) {
set();
}
else {
input.val('');
notifyError(val);
}
} else {
if (picker.date.isValid) {
picker.setValue(null);
Expand Down Expand Up @@ -633,8 +673,10 @@
else {
newDate = moment(picker.date).subtract(1, unit);
}
if (newDate.isAfter(picker.options.endDate) || newDate.subtract(1, unit).isBefore(picker.options.startDate)) return;
if (isInDisableDates(newDate)) return;
if (newDate.isAfter(picker.options.endDate) || newDate.subtract(1, unit).isBefore(picker.options.startDate) || isInDisableDates(newDate)) {
notifyError(newDate.format(picker.format))
return;
}

if (direction == "add") {
picker.date.add(1, unit);
Expand Down Expand Up @@ -849,9 +891,10 @@
picker.unset = false;
}
var d = moment(newDate);
if (!d.isValid())
if (!d.isValid()) {
throw new Error("Couldn't parase date or is invalid");

notifyError(newDate.format(picker.format));
}
picker.date = d;
set();
picker.viewDate = moment({ y: picker.date.year(), M: picker.date.month() });
Expand Down

0 comments on commit 5a349e4

Please sign in to comment.