DEV: allows time-input to be clearable (#9277)
This commit is contained in:
parent
dbc323e12a
commit
6acbd1bedf
|
@ -32,10 +32,14 @@ export default Component.extend({
|
||||||
didUpdateAttrs() {
|
didUpdateAttrs() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
|
||||||
if (this._picker && typeof date === "string") {
|
if (this._picker && typeof this.date === "string") {
|
||||||
const [year, month, day] = this.date.split("-").map(x => parseInt(x, 10));
|
const [year, month, day] = this.date.split("-").map(x => parseInt(x, 10));
|
||||||
this._picker.setDate(new Date(year, month - 1, day), true);
|
this._picker.setDate(new Date(year, month - 1, day), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._picker && !this.date) {
|
||||||
|
this._picker.setDate(null);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_loadPikadayPicker(container) {
|
_loadPikadayPicker(container) {
|
||||||
|
|
|
@ -5,6 +5,7 @@ export default Component.extend({
|
||||||
classNames: ["d-date-time-input"],
|
classNames: ["d-date-time-input"],
|
||||||
date: null,
|
date: null,
|
||||||
showTime: true,
|
showTime: true,
|
||||||
|
clearable: false,
|
||||||
|
|
||||||
_hours: computed("date", function() {
|
_hours: computed("date", function() {
|
||||||
return this.date && this.showTime ? new Date(this.date).getHours() : null;
|
return this.date && this.showTime ? new Date(this.date).getHours() : null;
|
||||||
|
@ -15,6 +16,10 @@ export default Component.extend({
|
||||||
}),
|
}),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
onClear() {
|
||||||
|
this.onChange(null);
|
||||||
|
},
|
||||||
|
|
||||||
onChangeTime(time) {
|
onChangeTime(time) {
|
||||||
if (this.onChange) {
|
if (this.onChange) {
|
||||||
const date = new Date(this.date);
|
const date = new Date(this.date);
|
||||||
|
|
|
@ -30,5 +30,6 @@
|
||||||
date=to
|
date=to
|
||||||
onChange=(action "_onChange" (hash prop="to"))
|
onChange=(action "_onChange" (hash prop="to"))
|
||||||
showTime=showToTime
|
showTime=showToTime
|
||||||
|
clearable=true
|
||||||
}}
|
}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -6,4 +6,8 @@
|
||||||
minutes=_minutes
|
minutes=_minutes
|
||||||
onChange=(action "onChangeTime")
|
onChange=(action "onChangeTime")
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
{{#if clearable}}
|
||||||
|
{{d-button icon="times" action=(action "onClear")}}
|
||||||
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
Loading…
Reference in New Issue