1
0

feat: use withDefaults for Password

This commit is contained in:
Dominik Pschenitschni 2024-07-06 12:05:19 +02:00 committed by konrad
parent 8ad7e7c905
commit 577f5ae69a

View File

@ -32,33 +32,32 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import {ref, watch} from 'vue' import {ref, watchEffect} from 'vue'
import {useDebounceFn} from '@vueuse/core' import {useDebounceFn} from '@vueuse/core'
import {useI18n} from 'vue-i18n' import {useI18n} from 'vue-i18n'
import BaseButton from '@/components/base/BaseButton.vue' import BaseButton from '@/components/base/BaseButton.vue'
const props = defineProps({ const props = withDefaults(defineProps<{
tabindex: String, modelValue: string,
modelValue: String, tabindex?: string,
// This prop is a workaround to trigger validation from the outside when the user never had focus in the input. // This prop is a workaround to trigger validation from the outside when the user never had focus in the input.
validateInitially: Boolean, validateInitially?: boolean,
validateMinLength: { validateMinLength?: boolean,
type: Boolean, }>(), {
default: true, validateMinLength: true,
},
}) })
const emit = defineEmits(['submit', 'update:modelValue'])
const emit = defineEmits<{
'update:modelValue': [value: string],
'submit': [event: Event],
}>()
const {t} = useI18n() const {t} = useI18n()
const passwordFieldType = ref('password') const passwordFieldType = ref('password')
const password = ref('') const password = ref('')
const isValid = ref<true | string>(props.validateInitially === true ? true : '') const isValid = ref<true | string>(props.validateInitially === true ? true : '')
const validateAfterFirst = ref(false) const validateAfterFirst = ref(false)
watch( watchEffect(() => props.validateInitially && validate())
() => props.validateInitially,
() => props.validateInitially && validate(),
{immediate: true},
)
const validate = useDebounceFn(() => { const validate = useDebounceFn(() => {
if (password.value === '') { if (password.value === '') {