UX: minor local-dates form improvements (#7360)

This commit is contained in:
Joffrey JAFFEUX 2019-04-11 14:03:53 +02:00 committed by GitHub
parent 7226240df3
commit 46dc38e5a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -307,6 +307,14 @@ export default Ember.Component.extend({
},
actions: {
setTime(event) {
this._setTimeIfValid(event.target.value, "time");
},
setToTime(event) {
this._setTimeIfValid(event.target.value, "toTime");
},
eraseToDateTime() {
this.setProperties({ toDate: null, toTime: null });
this._setPickerDate(null);
@ -340,6 +348,17 @@ export default Ember.Component.extend({
}
},
_setTimeIfValid(time, key) {
if (Ember.isEmpty(time)) {
this.set(key, null);
return;
}
if (/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/.test(time)) {
this.set(key, time);
}
},
_setupPicker() {
return new Ember.RSVP.Promise(resolve => {
loadScript("/javascripts/pikaday.js").then(() => {
@ -352,6 +371,7 @@ export default Ember.Component.extend({
firstDay: 1,
defaultDate: moment(this.get("date"), this.dateFormat).toDate(),
setDefaultDate: true,
keyboardInput: false,
i18n: {
previousMonth: I18n.t("dates.previous_month"),
nextMonth: I18n.t("dates.next_month"),

View File

@ -54,7 +54,7 @@
{{#if fromSelected}}
<div class="time-pickers">
{{d-icon "far-clock"}}
{{input input=(mut time) type="time" value=time class="time-picker"}}
{{input maxlength=5 placeholder="hh:mm" input=(action "setTime") type="time" value=(unbound time) class="time-picker"}}
</div>
{{/if}}
@ -62,7 +62,7 @@
{{#if toDate}}
<div class="time-pickers">
{{d-icon "far-clock"}}
{{input input=(mut toTime) type="time" value=toTime class="time-picker"}}
{{input maxlength=5 placeholder="hh:mm" input=(action "setToTime") type="time" value=(unbound toTime) class="time-picker"}}
</div>
{{/if}}
{{/if}}