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

Support time in oh-input widget #2214

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<f7-input v-if="!config.item || !config.sendButton" class="input-field" ref="input" v-bind="config" :value="(config.type.indexOf('date') === 0) ? valueForDatepicker : value"
<f7-input v-if="!config.item || !config.sendButton" class="input-field" ref="input" v-bind="config" :value="(config.type.indexOf('date') === 0 || config.type === 'time') ? valueForDatepicker : value"
:calendar-params="calendarParams" :step="config.step ? config.step : 'any'"
@input="$evt => updated($evt.target.value)" :change="updated" @calendar:change="updated" @texteditor:change="updated" @colorpicker:change="updated" />
<f7-row no-gap v-else class="oh-input-with-send-button">
<f7-input class="input-field col-90" ref="input" v-bind="config" :value="(config.type.indexOf('date') === 0) ? valueForDatepicker : value"
<f7-input class="input-field col-90" ref="input" v-bind="config" :value="(config.type.indexOf('date') === 0 || config.type === 'time') ? valueForDatepicker : value"
:calendar-params="calendarParams" :step="config.step ? config.step : 'any'"
@input="$evt => updated($evt.target.value)" :change="updated" @calendar:change="updated" @texteditor:change="updated" @colorpicker:change="updated" />
<f7-button class="send-button col-10" v-if="this.config.sendButton" @click.stop="sendButtonClicked" v-bind="config.sendButtonConfig || { iconMaterial: 'done', iconColor: 'gray' }" />
Expand Down Expand Up @@ -76,6 +76,8 @@ export default {
return dayjs(datetime).format('YYYY-MM-DD')
case 'datetime-local':
return dayjs(datetime).format('YYYY-MM-DDTHH:mm')
case 'time':
return dayjs(datetime).format('HH:mm:ss')
default:
return null
}
Expand All @@ -87,6 +89,18 @@ export default {
value = this.$$(this.$refs.input.$el).find('.text-editor-content')[0].innerHTML
if (value === this.value) return
}
if (this.config.type === 'time') {
const oldDate = dayjs(Array.isArray[this.value] ? this.value[0] : this.value).set('millisecond', 0)
let time = value.match(/(?<hour>[0-9]{2}):(?<minute>[0-9]{2})(:(?<second>[0-9]{2}))?/).groups
if (isNaN(time.hour) || isNaN(time.minute)) return
value = dayjs(oldDate).set('hour', time.hour).set('minute', time.minute).set('second', isNaN(time.second) ? 0 : time.second).set('millisecond', 0).format()
if ((new Date(oldDate)).getTime() === (new Date(value)).getTime()) return
}
if (this.config.type === 'date') {
const oldDate = dayjs(Array.isArray[this.value] ? this.value[0] : this.value).set('millisecond', 0)
value = dayjs(value).set('hour', oldDate.get('hour')).set('minute', oldDate.get('minute')).set('second', oldDate.get('second')).set('millisecond', 0).format()
if ((new Date(oldDate)).getTime() === (new Date(value)).getTime()) return
}
if (this.config.type === 'datepicker' && Array.isArray(value) && this.valueForDatepicker[0].getTime() === value[0].getTime()) return
if (this.config.sendButton) {
this.$set(this, 'pendingUpdate', value)
Expand Down