Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the user to clear input and trigger an event with the change. #225

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions js/foundation-datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@
this.setDaysOfWeekDisabled(options.daysOfWeekDisabled || this.element.data('date-days-of-week-disabled'));
this.setDatesDisabled(options.datesDisabled || this.element.data('dates-disabled'));

if (this.initialDate != null) {
this.date = this.viewDate = DPGlobal.parseDate(this.initialDate, this.format, this.language);
this.setValue();
}

this.fillDow();
this.fillMonths();
this.update();
Expand Down Expand Up @@ -432,27 +437,29 @@
if (arguments && arguments.length && (typeof arguments[0] === 'string' || arguments[0] instanceof Date)) {
date = arguments[0];
fromArgs = true;
}
else if (!currentVal && this.initialDate != null) { // If value is not set, set it to the initialDate
date = this.initialDate
}
else {
date = this.isInput ? this.element.val() : this.element.data('date') || this.element.find('input').val();
}

if (date && date.length > this.formatText.length) {
$(this.picker).addClass('is-invalid')
$(this.element).addClass('is-invalid-input')
return;
} else {
$(this.picker).removeClass('is-invalid')
$(this.element).removeClass('is-invalid-input')

}

this.date = DPGlobal.parseDate(date, this.format, this.language);
this.date = DPGlobal.parseDate(date, this.format, this.language);

if (fromArgs || this.initialDate != null) this.setValue();
if (fromArgs) {
this.setValue();
} else if (currentVal == "") {
this.element.trigger({
type: 'changeDate',
date: null
});
}

if (this.date < this.startDate) {
this.viewDate = new Date(this.startDate.valueOf());
Expand Down Expand Up @@ -507,7 +514,7 @@
today = new Date(),
titleFormat = dates[this.language].titleFormat || dates['en'].titleFormat;
// this.picker.find('.datepicker-days thead th.date-switch')
// .text(DPGlobal.formatDate(new UTCDate(year, month), titleFormat, this.language));
// .text(DPGlobal.formatDate(new UTCDate(year, month), titleFormat, this.language));

this.picker.find('.datepicker-days thead th:eq(1)')
.text(dates[this.language].months[month] + ' ' + year);
Expand Down Expand Up @@ -1099,25 +1106,25 @@
}
}
/*
vitalets: fixing bug of very special conditions:
jquery 1.7.1 + webkit + show inline datepicker in bootstrap popover.
Method show() does not set display css correctly and datepicker is not shown.
Changed to .css('display', 'block') solve the problem.
See https://github.com/vitalets/x-editable/issues/37
vitalets: fixing bug of very special conditions:
jquery 1.7.1 + webkit + show inline datepicker in bootstrap popover.
Method show() does not set display css correctly and datepicker is not shown.
Changed to .css('display', 'block') solve the problem.
See https://github.com/vitalets/x-editable/issues/37

In jquery 1.7.2+ everything works fine.
In jquery 1.7.2+ everything works fine.
*/
//this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
this.picker.find('>div').hide().filter('.datepicker-' + DPGlobal.modes[this.viewMode].clsName).css('display', 'block');
this.updateNavArrows();
},
changeViewDate: function(date) {
this.date = date;
this.viewDate = date;
this.fill();
},

changeViewDate: function(date) {
this.date = date;
this.viewDate = date;
this.fill();
},

reset: function(e) {
this._setDate(null, 'date');
}
Expand Down
Loading