Skip to content

A platform for community discussion. Free, open, simple.

UX: sets min date on calendar when initial date is set (#7361)

Joffrey JAFFEUX7dd684744c04
diff --git a/plugins/discourse-local-dates/assets/javascripts/discourse/components/discourse-local-dates-create-form.js.es6 b/plugins/discourse-local-dates/assets/javascripts/discourse/components/discourse-local-dates-create-form.js.es6
index f2c3c1096c4..f154cb1ce08 100644
--- a/plugins/discourse-local-dates/assets/javascripts/discourse/components/discourse-local-dates-create-form.js.es6
+++ b/plugins/discourse-local-dates/assets/javascripts/discourse/components/discourse-local-dates-create-form.js.es6
@@ -323,11 +323,13 @@ export default Ember.Component.extend({
focusFrom() {
this.setProperties({ fromSelected: true, toSelected: false });
this._setPickerDate(this.get("fromConfig.date"));
+ this._setPickerMinDate(null);
},
focusTo() {
this.setProperties({ toSelected: true, fromSelected: false });
this._setPickerDate(this.get("toConfig.date"));
+ this._setPickerMinDate(this.get("fromConfig.date"));
},
advancedMode() {
@@ -397,6 +399,17 @@ export default Ember.Component.extend({
});
},
+ _setPickerMinDate(date) {
+ console.log("_setPickerMinDate", date);
+ if (date && !moment(date, this.dateFormat).isValid()) {
+ date = null;
+ }
+
+ Ember.run.schedule("afterRender", () => {
+ this._picker.setMinDate(moment(date, this.dateFormat).toDate());
+ });
+ },
+
_setPickerDate(date) {
if (date && !moment(date, this.dateFormat).isValid()) {
date = null;