From 7550b4b124ba35d4159042f543944839e7d86989 Mon Sep 17 00:00:00 2001 From: Yehor Podporinov <50983498+yehor-podporinov@users.noreply.github.com> Date: Sun, 17 Sep 2023 15:25:06 +0300 Subject: [PATCH] Fix/Date form * fix tools-sidebar padding * fix starts-preview * updated project-info * updated navbar * updated footer * updated audits-page * updated images (high-res) * fix hash-function-form * removed footer of tools-sidebar * fix creare2-address-form * updated og-meta * renamed field: date -> day * fix date-form, refactoring * type number * utc initial date --------- Co-authored-by: Yehor Podporinov --- forms/DateForm.vue | 142 +++++++++++-------------- plugins/localization/resources/en.json | 4 +- 2 files changed, 66 insertions(+), 80 deletions(-) diff --git a/forms/DateForm.vue b/forms/DateForm.vue index 10b110c..02c939f 100644 --- a/forms/DateForm.vue +++ b/forms/DateForm.vue @@ -4,23 +4,24 @@

{{ $t('date-form.input-title') }}

{{ $t('date-form.output-title') }}

-
+

{{ item.label }}

@@ -38,39 +39,47 @@ import { AppCopy } from '#components' import { useFormValidation } from '@/composables' import { DatetimeField, InputField } from '@/fields' -import { ErrorHandler, integer, maxValue, minValue, required } from '@/helpers' +import { integer, maxValue, minValue, required } from '@/helpers' import { Time } from '@distributedlab/tools' -import { computed, onMounted, reactive, ref, watch } from 'vue' +import { computed, reactive } from 'vue' import { i18n } from '~/plugins/localization' const { t } = i18n.global -const calendarDate = ref(new Time().timestamp) -const maxDayInMonth = ref(31) -const currentDate = ref(null) const form = reactive({ year: '', month: '', - date: '', + day: '', hour: '', minute: '', second: '', }) +const maxDayInMonth = computed(() => { + const year = Number(form.year) + const month = Number(form.month) - 1 + + if (!year && !month) return 31 + return new Time(new Date(year, month)).dayjs.daysInMonth() +}) + const rules = computed(() => ({ year: { required, integer, - minValue: minValue(1970), + minValue: minValue(1924), maxValue: maxValue(10000), }, month: { required, integer, - minValue: minValue(1), + minValue: { + /** Date object with month of 1924 before May works incorrectly */ + ...(form.year === '1924' ? minValue(5) : minValue(1)), + }, maxValue: maxValue(12), }, - date: { + day: { required, integer, minValue: minValue(1), @@ -91,74 +100,51 @@ const rules = computed(() => ({ }, })) -const { isFormValid, getFieldErrorMessage, touchField, isFieldsValid } = - useFormValidation(form, rules) +const { getFieldErrorMessage, isFormValid, touchField } = useFormValidation( + form, + rules, +) + +const setForm = (time: Time) => { + form.year = String(time.get('year')) + form.month = String(time.get('month') + 1) + form.day = String(time.get('date')) + form.hour = String(time.get('hour')) + form.minute = String(time.get('minute')) + form.second = String(time.get('second')) +} + +setForm(new Time().utc()) + +const localTime = computed