modificaciones necesarias para aplicar a VnSelectCreate

This commit is contained in:
William Buezas 2023-12-18 12:06:07 -03:00
parent 5a1d4e90c9
commit 65251f9b13
3 changed files with 11 additions and 23 deletions

View File

@ -57,7 +57,7 @@ const $props = defineProps({
}, },
}); });
const emit = defineEmits(['onFetch']); const emit = defineEmits(['onFetch', 'onDataSaved']);
defineExpose({ defineExpose({
save, save,
@ -114,7 +114,7 @@ async function fetch() {
} }
async function save() { async function save() {
if (!hasChanges.value) { if ($props.observeFormChanges && !hasChanges.value) {
notify('globals.noChanges', 'negative'); notify('globals.noChanges', 'negative');
return; return;
} }
@ -127,6 +127,7 @@ async function save() {
} else { } else {
await axios.patch($props.urlUpdate || $props.url, formData.value); await axios.patch($props.urlUpdate || $props.url, formData.value);
} }
emit('onDataSaved', formData.value);
} catch (err) { } catch (err) {
notify('errors.create', 'negative'); notify('errors.create', 'negative');
} }

View File

@ -16,10 +16,6 @@ const $props = defineProps({
type: Array, type: Array,
default: () => [], default: () => [],
}, },
optionLabel: {
type: String,
default: '',
},
rolesAllowedToCreate: { rolesAllowedToCreate: {
type: Array, type: Array,
default: () => ['developer'], default: () => ['developer'],
@ -48,7 +44,7 @@ const toggleForm = () => {
</script> </script>
<template> <template>
<VnSelectFilter v-model="value" :options="options"> <VnSelectFilter v-model="value" :options="options" v-bind="$attrs">
<template v-if="isAllowedToCreate" #append> <template v-if="isAllowedToCreate" #append>
<QIcon <QIcon
@click.stop.prevent="toggleForm()" @click.stop.prevent="toggleForm()"
@ -57,7 +53,7 @@ const toggleForm = () => {
class="add-icon" class="add-icon"
/> />
<QDialog v-model="showForm" transition-show="scale" transition-hide="scale"> <QDialog v-model="showForm" transition-show="scale" transition-hide="scale">
<slot name="form" @close-form="toggleForm()" /> <slot name="form" />
</QDialog> </QDialog>
</template> </template>
<template v-for="(_, slotName) in $slots" #[slotName]="slotData" :key="slotName"> <template v-for="(_, slotName) in $slots" #[slotName]="slotData" :key="slotName">

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { ref, toRefs, watch, computed } from 'vue'; import { ref, toRefs, computed } from 'vue';
const emit = defineEmits(['update:modelValue', 'update:options']); const emit = defineEmits(['update:modelValue', 'update:options']);
const $props = defineProps({ const $props = defineProps({
@ -24,16 +24,11 @@ const $props = defineProps({
default: true, default: true,
}, },
}); });
const { optionLabel, options } = toRefs($props);
const myOptions = ref([]);
const myOptionsOriginal = ref([]);
const vnSelectRef = ref(null);
function setOptions(data) { const { optionLabel } = toRefs($props);
myOptions.value = JSON.parse(JSON.stringify(data)); const myOptions = ref([]);
myOptionsOriginal.value = JSON.parse(JSON.stringify(data)); const myOptionsOriginal = computed(() => $props.options);
} const vnSelectRef = ref(null);
setOptions(options.value);
const filter = (val, options) => { const filter = (val, options) => {
const search = val.toString().toLowerCase(); const search = val.toString().toLowerCase();
@ -69,10 +64,6 @@ const filterHandler = (val, update) => {
); );
}; };
watch(options, (newValue) => {
setOptions(newValue);
});
const value = computed({ const value = computed({
get() { get() {
return $props.modelValue; return $props.modelValue;