Skip to content

Commit 9486c3e

Browse files
committed
fix: enhance edit functionality in InPlaceEdit component with change detection
1 parent 56d15b2 commit 9486c3e

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

custom/InPlaceEdit.vue

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
</div>
1414

1515
<!-- Edit mode -->
16-
<div v-else class="flex items-center min-w-full max-w-full gap-2">
16+
<div v-else class="flex items-center gap-2 min-w-[200px]">
1717
<ColumnValueInputWrapper
1818
ref="input"
19+
class="flex-grow"
1920
:source="'edit'"
2021
:column="column"
2122
:currentValues="currentValues"
@@ -27,8 +28,11 @@
2728
<div class="flex gap-1">
2829
<button
2930
@click="saveEdit"
30-
:disabled="saving"
31-
class="text-green-600 hover:text-green-700 dark:text-green-500 dark:hover:text-green-400"
31+
:disabled="!isChanged || saving"
32+
:class="[
33+
'text-green-600 dark:text-green-500 hover:text-green-700 dark:hover:text-green-400',
34+
(!isChanged || saving) ? 'opacity-50 cursor-not-allowed pointer-events-none' : ''
35+
]"
3236
>
3337
<IconCheckOutline class="w-5 h-5" />
3438
</button>
@@ -45,7 +49,7 @@
4549
</template>
4650

4751
<script setup lang="ts">
48-
import { ref } from 'vue';
52+
import { ref, computed } from 'vue';
4953
import { IconPenSolid, IconCheckOutline, IconXOutline } from '@iconify-prerendered/vue-flowbite';
5054
import { callAdminForthApi } from '@/utils';
5155
import { showErrorTost, showSuccesTost } from '@/composables/useFrontendApi';
@@ -63,6 +67,12 @@ const columnOptions = ref({});
6367
const mode = ref('edit');
6468
const currentValues = ref({});
6569
const unmasked = ref({});
70+
const isChanged = computed(() => {
71+
const original = props.record[props.column.name];
72+
const current = currentValues.value[props.column.name];
73+
74+
return JSON.stringify(original) !== JSON.stringify(current);
75+
});
6676
6777
function startEdit() {
6878
const value = props.record[props.column.name];

0 commit comments

Comments
 (0)