feat: show formatted float fields in Modal & data fields

This commit is contained in:
Shariq Ansari 2024-12-25 18:20:00 +05:30
parent 0d2ca4cb4a
commit a91d8e449f
3 changed files with 29 additions and 9 deletions

View File

@ -190,15 +190,21 @@
:placeholder="getPlaceholder(field)"
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
v-else-if="field.type === 'Currency'"
type="text"
:value="getFormattedCurrency(field.name, data)"
:placeholder="getPlaceholder(field)"
:disabled="Boolean(field.read_only)"
@change="
data[field.name] = flt($event.target.value)
"
@change="data[field.name] = flt($event.target.value)"
/>
<FormControl
v-else
@ -243,7 +249,7 @@ const props = defineProps({
},
})
const { getFormattedCurrency } = getMeta(props.doctype)
const { getFormattedFloat, getFormattedCurrency } = getMeta(props.doctype)
const { getUser } = usersStore()
const hasTabs = computed(() => !props.tabs[0].no_tabs)

View File

@ -168,6 +168,15 @@
@change="(data) => emit('update', field.name, data)"
/>
</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
v-else-if="field.type === 'currency'"
class="form-control"
@ -175,9 +184,7 @@
:value="getFormattedCurrency(field.name, data)"
:placeholder="field.placeholder"
:debounce="500"
@change.stop="
emit('update', field.name, flt($event.target.value))
"
@change.stop="emit('update', field.name, flt($event.target.value))"
/>
<FormControl
v-else
@ -235,7 +242,7 @@ const props = defineProps({
},
})
const { getFormattedCurrency } = getMeta(props.doctype)
const { getFormattedFloat, getFormattedCurrency } = getMeta(props.doctype)
const { getUser } = usersStore()
const emit = defineEmits(['update'])

View File

@ -1,5 +1,5 @@
import { createResource } from 'frappe-ui'
import { formatCurrency } from '@/utils/numberFormat.js'
import { formatCurrency, formatNumber } from '@/utils/numberFormat.js'
import { reactive } from 'vue'
const doctypeMeta = reactive({})
@ -25,6 +25,12 @@ export function getMeta(doctype) {
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) {
let currency = window.sysdefaults.currency || 'USD'
@ -44,6 +50,7 @@ export function getMeta(doctype) {
return {
meta,
doctypeMeta,
getFormattedFloat,
getFormattedCurrency,
}
}