feat: show formatted float fields in Modal & data fields
This commit is contained in:
parent
0d2ca4cb4a
commit
a91d8e449f
@ -190,15 +190,21 @@
|
|||||||
:placeholder="getPlaceholder(field)"
|
:placeholder="getPlaceholder(field)"
|
||||||
v-model="data[field.name]"
|
v-model="data[field.name]"
|
||||||
/>
|
/>
|
||||||
|
<FormControl
|
||||||
|
v-else-if="field.type === 'Float'"
|
||||||
|
type="text"
|
||||||
|
:value="getFormattedFloat(field.name, data)"
|
||||||
|
:placeholder="getPlaceholder(field)"
|
||||||
|
:disabled="Boolean(field.read_only)"
|
||||||
|
@change="data[field.name] = flt($event.target.value)"
|
||||||
|
/>
|
||||||
<FormControl
|
<FormControl
|
||||||
v-else-if="field.type === 'Currency'"
|
v-else-if="field.type === 'Currency'"
|
||||||
type="text"
|
type="text"
|
||||||
:value="getFormattedCurrency(field.name, data)"
|
:value="getFormattedCurrency(field.name, data)"
|
||||||
:placeholder="getPlaceholder(field)"
|
:placeholder="getPlaceholder(field)"
|
||||||
:disabled="Boolean(field.read_only)"
|
:disabled="Boolean(field.read_only)"
|
||||||
@change="
|
@change="data[field.name] = flt($event.target.value)"
|
||||||
data[field.name] = flt($event.target.value)
|
|
||||||
"
|
|
||||||
/>
|
/>
|
||||||
<FormControl
|
<FormControl
|
||||||
v-else
|
v-else
|
||||||
@ -243,7 +249,7 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const { getFormattedCurrency } = getMeta(props.doctype)
|
const { getFormattedFloat, getFormattedCurrency } = getMeta(props.doctype)
|
||||||
const { getUser } = usersStore()
|
const { getUser } = usersStore()
|
||||||
|
|
||||||
const hasTabs = computed(() => !props.tabs[0].no_tabs)
|
const hasTabs = computed(() => !props.tabs[0].no_tabs)
|
||||||
|
|||||||
@ -168,6 +168,15 @@
|
|||||||
@change="(data) => emit('update', field.name, data)"
|
@change="(data) => emit('update', field.name, data)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<FormControl
|
||||||
|
v-else-if="field.type === 'float'"
|
||||||
|
class="form-control"
|
||||||
|
type="text"
|
||||||
|
:value="getFormattedFloat(field.name, data)"
|
||||||
|
:placeholder="field.placeholder"
|
||||||
|
:debounce="500"
|
||||||
|
@change.stop="emit('update', field.name, flt($event.target.value))"
|
||||||
|
/>
|
||||||
<FormControl
|
<FormControl
|
||||||
v-else-if="field.type === 'currency'"
|
v-else-if="field.type === 'currency'"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
@ -175,9 +184,7 @@
|
|||||||
:value="getFormattedCurrency(field.name, data)"
|
:value="getFormattedCurrency(field.name, data)"
|
||||||
:placeholder="field.placeholder"
|
:placeholder="field.placeholder"
|
||||||
:debounce="500"
|
:debounce="500"
|
||||||
@change.stop="
|
@change.stop="emit('update', field.name, flt($event.target.value))"
|
||||||
emit('update', field.name, flt($event.target.value))
|
|
||||||
"
|
|
||||||
/>
|
/>
|
||||||
<FormControl
|
<FormControl
|
||||||
v-else
|
v-else
|
||||||
@ -235,7 +242,7 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const { getFormattedCurrency } = getMeta(props.doctype)
|
const { getFormattedFloat, getFormattedCurrency } = getMeta(props.doctype)
|
||||||
const { getUser } = usersStore()
|
const { getUser } = usersStore()
|
||||||
|
|
||||||
const emit = defineEmits(['update'])
|
const emit = defineEmits(['update'])
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { createResource } from 'frappe-ui'
|
import { createResource } from 'frappe-ui'
|
||||||
import { formatCurrency } from '@/utils/numberFormat.js'
|
import { formatCurrency, formatNumber } from '@/utils/numberFormat.js'
|
||||||
import { reactive } from 'vue'
|
import { reactive } from 'vue'
|
||||||
|
|
||||||
const doctypeMeta = reactive({})
|
const doctypeMeta = reactive({})
|
||||||
@ -25,6 +25,12 @@ export function getMeta(doctype) {
|
|||||||
meta.fetch()
|
meta.fetch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFormattedFloat(fieldname, doc) {
|
||||||
|
let df = doctypeMeta[doctype]?.fields.find((f) => f.fieldname == fieldname)
|
||||||
|
let precision = df?.precision || null
|
||||||
|
return formatNumber(doc[fieldname], "", precision)
|
||||||
|
}
|
||||||
|
|
||||||
function getFormattedCurrency(fieldname, doc) {
|
function getFormattedCurrency(fieldname, doc) {
|
||||||
let currency = window.sysdefaults.currency || 'USD'
|
let currency = window.sysdefaults.currency || 'USD'
|
||||||
|
|
||||||
@ -44,6 +50,7 @@ export function getMeta(doctype) {
|
|||||||
return {
|
return {
|
||||||
meta,
|
meta,
|
||||||
doctypeMeta,
|
doctypeMeta,
|
||||||
|
getFormattedFloat,
|
||||||
getFormattedCurrency,
|
getFormattedCurrency,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user