2020-10-24 12:50:08 -07:00
|
|
|
<template>
|
2022-01-13 08:41:31 -08:00
|
|
|
<draggable tag="ul" v-model="iVal" handle=".handle" ghostClass="ghost" @end="$emit('input', iVal)" @add="$emit('input', iVal)" class="list-unstyled" :group="group">
|
2020-10-25 04:30:55 -07:00
|
|
|
<li v-for="(v, i) in iVal" ref="items">
|
2021-08-29 01:40:37 -07:00
|
|
|
<div>
|
|
|
|
<div class="input-group input-group-sm mb-1">
|
|
|
|
<button class="btn btn-light border handle" type="button" :aria-label="$t('table.sort')">
|
|
|
|
<Icon v="bars"/>
|
|
|
|
</button>
|
|
|
|
<slot v-bind:val="iVal[i]" v-bind:update="curry(update)(i)">
|
|
|
|
<input v-model="iVal[i]" type="text" class="form-control" required/>
|
|
|
|
</slot>
|
|
|
|
<button class="btn btn-outline-danger" type="button" @click.prevent="remove(i)" :aria-label="$t('crud.remove')">
|
|
|
|
<Icon v="times"/>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<slot name="validation" v-bind:val="iVal[i]"></slot>
|
2020-10-24 12:50:08 -07:00
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
|
2020-10-25 04:30:55 -07:00
|
|
|
<li slot="footer">
|
2021-01-22 14:54:24 -08:00
|
|
|
<button class="btn btn-outline-success w-100 btn-sm" type="button" @click.prevent="add" :aria-label="$t('crud.add')">
|
2020-10-24 12:50:08 -07:00
|
|
|
<Icon v="plus"/>
|
|
|
|
</button>
|
|
|
|
</li>
|
2020-10-25 04:30:55 -07:00
|
|
|
</draggable>
|
2020-10-24 12:50:08 -07:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { curry } from "../src/helpers";
|
2020-10-25 04:30:55 -07:00
|
|
|
import draggable from 'vuedraggable'
|
2020-10-24 12:50:08 -07:00
|
|
|
|
|
|
|
export default {
|
2020-10-25 04:30:55 -07:00
|
|
|
components: {
|
|
|
|
draggable,
|
|
|
|
},
|
2020-10-24 12:50:08 -07:00
|
|
|
props: {
|
|
|
|
value: {},
|
|
|
|
prototype: { 'default': '' },
|
2020-10-25 04:30:55 -07:00
|
|
|
group: {},
|
2020-10-24 12:50:08 -07:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2020-10-25 04:30:55 -07:00
|
|
|
iVal: this.value,
|
2020-10-24 12:50:08 -07:00
|
|
|
curry: curry,
|
|
|
|
}
|
|
|
|
},
|
2020-10-25 04:30:55 -07:00
|
|
|
watch: {
|
|
|
|
value() {
|
|
|
|
this.iVal = this.value;
|
|
|
|
}
|
|
|
|
},
|
2020-10-24 12:50:08 -07:00
|
|
|
methods: {
|
|
|
|
remove(i) {
|
|
|
|
const v = [...this.value];
|
|
|
|
v.splice(i, 1);
|
|
|
|
this.$emit('input', v);
|
|
|
|
},
|
|
|
|
add() {
|
|
|
|
this.$emit('input', [...this.value, this.prototype]);
|
|
|
|
this.$nextTick(_ => {
|
2020-10-31 06:54:56 -07:00
|
|
|
this.$refs.items[this.value.length - 1].querySelector('input,textarea,select').focus();
|
2020-10-24 12:50:08 -07:00
|
|
|
});
|
|
|
|
},
|
|
|
|
update(i, val) {
|
|
|
|
const v = [...this.value];
|
|
|
|
v[i] = val;
|
|
|
|
this.$emit('input', v);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
2020-10-25 04:30:55 -07:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.ghost {
|
|
|
|
opacity: 0.5;
|
|
|
|
background: #c8ebfb;
|
|
|
|
}
|
|
|
|
</style>
|