Fix opening repeater row when creating new one

This commit is contained in:
Nitwel
2020-10-07 17:52:18 +02:00
parent 248d648ba0
commit 05dcbf945b
4 changed files with 23 additions and 10 deletions

View File

@@ -1,11 +1,11 @@
<template>
<div class="v-item">
<slot v-bind="{ active, toggle }" />
<slot v-bind="{ 'active': isActive, toggle }" />
</div>
</template>
<script lang="ts">
import { defineComponent } from '@vue/composition-api';
import { defineComponent, toRefs } from '@vue/composition-api';
import { useGroupable } from '@/composables/groupable';
export default defineComponent({
@@ -18,14 +18,25 @@ export default defineComponent({
type: String,
default: 'item-group',
},
active: {
type: Boolean,
default: undefined
},
watch: {
type: Boolean,
default: true
}
},
setup(props) {
const { active, toggle } = useGroupable({
const {active} = toRefs(props)
const { active: isActive, toggle } = useGroupable({
value: props.value,
group: props.scope,
watch: props.watch,
active
});
return { active, toggle };
return { isActive, toggle };
},
});
</script>

View File

@@ -149,10 +149,15 @@ export function useGroupableParent(
// Register a child within the context of this group
function register(item: GroupableInstance) {
items.value = [...items.value, item];
const value = getValueForItem(item)
// If you're required to select a value, make sure a value is selected on first render
if (selection.value.length === 0 && options?.mandatory?.value === true && items.value.length === 1) {
selection.value = [getValueForItem(item)];
selection.value = [value];
}
if(item.active.value && selection.value.includes(value) === false) {
toggle(item)
}
}

View File

@@ -1,5 +1,5 @@
<template>
<v-item class="row" v-slot:default="{ active, toggle }">
<v-item class="row" v-slot:default="{ active, toggle }" :active="true" :watch="false">
<repeater-row-header
:template="template"
:value="value"

View File

@@ -1,5 +1,5 @@
<template>
<v-item-group class="repeater" v-model="selection">
<v-item-group class="repeater">
<draggable :value="value" handle=".drag-handle" @input="onSort" :set-data="hideDragImage">
<repeater-row
v-for="(row, index) in value"
@@ -106,9 +106,6 @@ export default defineComponent({
newDefaults[field.field!] = field.schema?.default_value;
});
// select the new row
selection.value = [props.value?.length || 0];
if (props.value !== null) {
emitValue([...props.value, newDefaults]);
} else {