Files
docuseal/app/javascript/submission_form/date_step.vue
T

132 lines
3.0 KiB
Vue
Raw Normal View History

2023-10-26 21:26:08 +03:00
<template>
2024-01-07 14:19:21 +02:00
<div dir="auto">
2024-03-09 18:24:21 +02:00
<div
class="flex justify-between items-center w-full"
:class="{ 'mb-2': !field.description }"
>
2023-10-26 21:26:08 +03:00
<label
:for="field.uuid"
class="label text-2xl"
2024-03-09 18:24:21 +02:00
>
<MarkdownContent
v-if="field.title"
:string="field.title"
/>
<template v-else>
{{ field.name && showFieldNames ? field.name : t('date') }}
2024-06-13 14:24:37 +03:00
<template v-if="!field.required">
({{ t('optional') }})
</template>
2024-03-09 18:24:21 +02:00
</template>
2023-10-26 21:26:08 +03:00
</label>
<button
class="btn btn-outline btn-sm !normal-case font-normal"
2024-04-08 18:34:27 +03:00
@click.prevent="[setCurrentDate(), $emit('focus')]"
2023-10-26 21:26:08 +03:00
>
<IconCalendarCheck :width="16" />
{{ t('set_today') }}
</button>
</div>
2024-03-09 18:24:21 +02:00
<div
v-if="field.description"
class="mb-3 px-1"
dir="auto"
>
<MarkdownContent :string="field.description" />
</div>
2024-01-06 17:21:15 +02:00
<AppearsOn :field="field" />
2023-10-26 21:26:08 +03:00
<div class="text-center">
<input
2024-11-17 15:57:10 +02:00
:id="field.uuid"
2023-10-26 21:26:08 +03:00
ref="input"
v-model="value"
class="base-input !text-2xl text-center w-full"
:required="field.required"
type="date"
:name="`values[${field.uuid}]`"
2024-08-01 18:47:17 +03:00
@keydown.enter="onEnter"
2023-10-26 21:26:08 +03:00
@focus="$emit('focus')"
2024-10-15 19:24:30 +03:00
@paste="onPaste"
2023-10-26 21:26:08 +03:00
>
</div>
</div>
</template>
<script>
import { IconCalendarCheck } from '@tabler/icons-vue'
2024-01-06 17:21:15 +02:00
import AppearsOn from './appears_on'
2024-03-09 18:24:21 +02:00
import MarkdownContent from './markdown_content'
2023-10-26 21:26:08 +03:00
export default {
name: 'DateStep',
components: {
2024-01-06 17:21:15 +02:00
IconCalendarCheck,
2024-03-09 18:24:21 +02:00
MarkdownContent,
2024-01-06 17:21:15 +02:00
AppearsOn
2023-10-26 21:26:08 +03:00
},
inject: ['t'],
props: {
field: {
type: Object,
required: true
},
2024-01-24 23:20:53 +02:00
showFieldNames: {
type: Boolean,
required: false,
default: true
},
2023-10-26 21:26:08 +03:00
modelValue: {
type: String,
required: false,
default: ''
}
},
2024-08-01 18:47:17 +03:00
emits: ['update:model-value', 'focus', 'submit'],
2023-10-26 21:26:08 +03:00
computed: {
value: {
set (value) {
this.$emit('update:model-value', value)
},
get () {
return this.modelValue
}
}
},
methods: {
2024-08-01 18:47:17 +03:00
onEnter (e) {
if (this.modelValue) {
e.preventDefault()
this.$emit('submit')
}
},
2024-10-15 19:24:30 +03:00
onPaste (e) {
e.preventDefault()
let pasteData = e.clipboardData.getData('text').trim()
if (pasteData.match(/^\d{2}\.\d{2}\.\d{4}$/)) {
pasteData = pasteData.split('.').reverse().join('-')
}
const parsedDate = new Date(pasteData)
if (!isNaN(parsedDate)) {
const inputEl = this.$refs.input
inputEl.valueAsDate = new Date(parsedDate.getTime() - parsedDate.getTimezoneOffset() * 60000)
inputEl.dispatchEvent(new Event('input', { bubbles: true }))
}
},
2023-10-26 21:26:08 +03:00
setCurrentDate () {
const inputEl = this.$refs.input
inputEl.valueAsDate = new Date(new Date().getTime() - new Date().getTimezoneOffset() * 60000)
inputEl.dispatchEvent(new Event('input', { bubbles: true }))
}
}
}
</script>