2023-07-26 04:01:12 +02:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { useFieldArray } from 'vee-validate'
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
name: string
|
2023-08-07 16:39:06 +02:00
|
|
|
label: string
|
|
|
|
inputLabel: string
|
2023-11-07 18:45:21 +01:00
|
|
|
buttonLabel: string
|
2023-07-26 04:01:12 +02:00
|
|
|
type: HTMLInputElement['type']
|
2023-11-07 18:45:21 +01:00
|
|
|
placeholder?: string,
|
2023-07-26 04:01:12 +02:00
|
|
|
}>()
|
|
|
|
|
2023-08-07 16:39:06 +02:00
|
|
|
const group: Ref<HTMLElement | null> = ref(null)
|
2023-07-26 04:01:12 +02:00
|
|
|
const { remove, push, fields } = useFieldArray(props.name)
|
2023-08-07 16:39:06 +02:00
|
|
|
|
|
|
|
function onAdd() {
|
|
|
|
push('')
|
|
|
|
nextTick(() => {
|
|
|
|
// auto focus new input
|
|
|
|
const inputs = group.value?.querySelectorAll('input')
|
|
|
|
if (inputs && inputs.length) {
|
|
|
|
inputs[inputs.length - 1].focus()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-07-26 04:01:12 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-08-07 16:39:06 +02:00
|
|
|
<fieldset ref="group">
|
2023-08-28 19:15:59 +02:00
|
|
|
<legend class="text-xl mb-3">{{ label }}</legend>
|
2023-07-26 04:01:12 +02:00
|
|
|
|
2023-08-07 16:39:06 +02:00
|
|
|
<FormField
|
|
|
|
v-for="(field, idx) in fields"
|
|
|
|
:key="field.key"
|
|
|
|
:name="`${name}[${idx}]`"
|
|
|
|
:label="inputLabel"
|
|
|
|
class="mb-3"
|
|
|
|
sr-hide-label
|
|
|
|
>
|
2023-08-28 14:42:54 +02:00
|
|
|
<div class="join w-full">
|
2023-08-07 16:39:06 +02:00
|
|
|
<TextInput
|
|
|
|
:name="`${name}[${idx}]`"
|
|
|
|
:type="type"
|
|
|
|
:placeholder="placeholder"
|
2023-08-28 14:42:54 +02:00
|
|
|
class="join-item w-full"
|
2023-08-07 16:39:06 +02:00
|
|
|
/>
|
|
|
|
<YButton
|
|
|
|
variant="error"
|
|
|
|
icon="mdi:delete-forever"
|
|
|
|
icon-size="2em"
|
|
|
|
icon-only
|
|
|
|
:text="$t('remove')"
|
|
|
|
class="join-item px-3"
|
|
|
|
@click="remove(idx)"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</FormField>
|
2023-07-26 04:01:12 +02:00
|
|
|
|
2023-11-07 18:45:21 +01:00
|
|
|
<YButton :text="buttonLabel" @click="onAdd" />
|
2023-08-07 16:39:06 +02:00
|
|
|
</fieldset>
|
2023-07-26 04:01:12 +02:00
|
|
|
</template>
|