Add: Remove option in FormBuilder
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
45b559ea17
commit
a1b0f6496c
|
@ -1,20 +1,30 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="space-y-1">
|
<div class="space-y-1">
|
||||||
<span class="text-xs font-semibold text-gray-400">Optionen</span>
|
<span class="text-xs font-semibold text-gray-400">Optionen</span>
|
||||||
|
<div v-for="(option, index) in modelValue.options" :key="index" class="flex space-x-2">
|
||||||
<f-text
|
<f-text
|
||||||
v-for="(option, index) in modelValue.options"
|
|
||||||
:id="`options-${index}`"
|
:id="`options-${index}`"
|
||||||
:key="index"
|
|
||||||
size="sm"
|
size="sm"
|
||||||
|
class="grow"
|
||||||
:name="`options-${index}`"
|
:name="`options-${index}`"
|
||||||
:model-value="option"
|
:model-value="option"
|
||||||
@update:modelValue="$emit('update:modelValue', {...props.modelValue, options: props.modelValue.options.toSpliced(index, 1, $event)})"
|
@update:modelValue="$emit('update:modelValue', {...props.modelValue, options: setOption(props.modelValue.options, index, $event)})"
|
||||||
></f-text>
|
></f-text>
|
||||||
<ui-icon-button icon="plus" @click="$emit('update:modelValue', {...modelValue, options: [...modelValue.options, '']})">Option einfügen</ui-icon-button>
|
<ui-action-button
|
||||||
|
tooltip="Löschen"
|
||||||
|
icon="trash"
|
||||||
|
class="btn-danger"
|
||||||
|
@click="$emit('update:modelValue', {...modelValue, options: removeOption(modelValue.options, index)})"
|
||||||
|
></ui-action-button>
|
||||||
|
</div>
|
||||||
|
<ui-icon-button icon="plus" @click="$emit('update:modelValue', {...modelValue, options: addOption(modelValue.options)})">Option einfügen</ui-icon-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import useElements from './useElements.js';
|
||||||
|
const {addOption, setOption, removeOption} = useElements();
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
modelValue: {},
|
modelValue: {},
|
||||||
meta: {},
|
meta: {},
|
||||||
|
|
|
@ -1,16 +1,23 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="space-y-1">
|
<div class="space-y-1">
|
||||||
<span class="text-xs font-semibold text-gray-400">Optionen</span>
|
<span class="text-xs font-semibold text-gray-400">Optionen</span>
|
||||||
|
<div v-for="(option, index) in modelValue.options" :key="index" class="flex space-x-2">
|
||||||
<f-text
|
<f-text
|
||||||
v-for="(option, index) in modelValue.options"
|
|
||||||
:id="`options-${index}`"
|
:id="`options-${index}`"
|
||||||
:key="index"
|
|
||||||
size="sm"
|
size="sm"
|
||||||
|
class="grow"
|
||||||
:name="`options-${index}`"
|
:name="`options-${index}`"
|
||||||
:model-value="option"
|
:model-value="option"
|
||||||
@update:modelValue="$emit('update:modelValue', {...props.modelValue, options: props.modelValue.options.toSpliced(index, 1, $event)})"
|
@update:modelValue="$emit('update:modelValue', {...props.modelValue, options: setOption(props.modelValue.options, index, $event)})"
|
||||||
></f-text>
|
></f-text>
|
||||||
<ui-icon-button icon="plus" @click="$emit('update:modelValue', {...modelValue, options: [...modelValue.options, '']})">Option einfügen</ui-icon-button>
|
<ui-action-button
|
||||||
|
tooltip="Löschen"
|
||||||
|
icon="trash"
|
||||||
|
class="btn-danger"
|
||||||
|
@click="$emit('update:modelValue', {...modelValue, options: removeOption(modelValue.options, index)})"
|
||||||
|
></ui-action-button>
|
||||||
|
</div>
|
||||||
|
<ui-icon-button icon="plus" @click="$emit('update:modelValue', {...modelValue, options: addOption(modelValue.options)})">Option einfügen</ui-icon-button>
|
||||||
</div>
|
</div>
|
||||||
<f-switch
|
<f-switch
|
||||||
id="fieldrequired"
|
id="fieldrequired"
|
||||||
|
@ -24,6 +31,9 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import useElements from './useElements.js';
|
||||||
|
const {addOption, setOption, removeOption} = useElements();
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
modelValue: {},
|
modelValue: {},
|
||||||
meta: {},
|
meta: {},
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
export default function useElements() {
|
||||||
|
function addOption(options) {
|
||||||
|
return [...options, ''];
|
||||||
|
}
|
||||||
|
|
||||||
|
function setOption(options, index, $event) {
|
||||||
|
return options.toSpliced(index, 1, $event);
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeOption(options, index) {
|
||||||
|
return options.toSpliced(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {addOption, setOption, removeOption};
|
||||||
|
}
|
Loading…
Reference in New Issue