fix: trigger on change in Field & SidePanelLayout for Select field

This commit is contained in:
Shariq Ansari 2025-05-01 18:03:04 +05:30
parent a30503ca5f
commit d37e585205
2 changed files with 21 additions and 4 deletions

View File

@ -31,6 +31,7 @@
:class="field.prefix ? 'prefix' : ''" :class="field.prefix ? 'prefix' : ''"
:options="field.options" :options="field.options"
v-model="data[field.fieldname]" v-model="data[field.fieldname]"
@change="(e) => fieldChange(e.target.value, field)"
:placeholder="getPlaceholder(field)" :placeholder="getPlaceholder(field)"
> >
<template v-if="field.prefix" #prefix> <template v-if="field.prefix" #prefix>
@ -195,6 +196,7 @@ import { getFormat, evaluateDependsOnValue } from '@/utils'
import { flt } from '@/utils/numberFormat.js' import { flt } from '@/utils/numberFormat.js'
import { getMeta } from '@/stores/meta' import { getMeta } from '@/stores/meta'
import { usersStore } from '@/stores/users' import { usersStore } from '@/stores/users'
import { useDocument } from '@/data/document'
import { Tooltip, DatePicker, DateTimePicker } from 'frappe-ui' import { Tooltip, DatePicker, DateTimePicker } from 'frappe-ui'
import { computed, inject } from 'vue' import { computed, inject } from 'vue'
@ -208,8 +210,11 @@ const preview = inject('preview')
const { getFormattedPercent, getFormattedFloat, getFormattedCurrency } = const { getFormattedPercent, getFormattedFloat, getFormattedCurrency } =
getMeta(doctype) getMeta(doctype)
const { getUser } = usersStore() const { getUser } = usersStore()
const { triggerOnChange } = useDocument(doctype, data.value.name)
const field = computed(() => { const field = computed(() => {
let field = props.field let field = props.field
if (field.fieldtype == 'Select' && typeof field.options === 'string') { if (field.fieldtype == 'Select' && typeof field.options === 'string') {
@ -265,6 +270,12 @@ const getPlaceholder = (field) => {
return __('Enter {0}', [__(field.label)]) return __('Enter {0}', [__(field.label)])
} }
} }
function fieldChange(value, df) {
data.value[df.fieldname] = value
triggerOnChange(df.fieldname)
}
</script> </script>
<style scoped> <style scoped>
:deep(.form-control.prefix select) { :deep(.form-control.prefix select) {

View File

@ -176,9 +176,7 @@
v-model="document.doc[field.fieldname]" v-model="document.doc[field.fieldname]"
:options="field.options" :options="field.options"
:placeholder="field.placeholder" :placeholder="field.placeholder"
@change.stop=" @change.stop="fieldChange($event.target.value, field)"
emit('update', field.fieldname, $event.target.value)
"
/> />
<Link <Link
v-else-if="field.fieldtype === 'User'" v-else-if="field.fieldtype === 'User'"
@ -428,7 +426,7 @@ const emit = defineEmits(['update', 'reload'])
const showSidePanelModal = ref(false) const showSidePanelModal = ref(false)
const { document } = useDocument(props.doctype, props.docname) const { document, triggerOnChange } = useDocument(props.doctype, props.docname)
const _sections = computed(() => { const _sections = computed(() => {
if (!props.sections?.length) return [] if (!props.sections?.length) return []
@ -481,6 +479,14 @@ function parsedField(field) {
return _field return _field
} }
async function fieldChange(value, df) {
document.doc[df.fieldname] = value
await triggerOnChange(df.fieldname)
document.save.submit()
}
function parsedSection(section, editButtonAdded) { function parsedSection(section, editButtonAdded) {
let isContactSection = section.name == 'contacts_section' let isContactSection = section.name == 'contacts_section'
section.showEditButton = !( section.showEditButton = !(