fix: handle different fieldtypes in Section Fields component

This commit is contained in:
Shariq Ansari 2023-11-22 17:50:56 +05:30
parent 267f42a7fe
commit fa0767e90a
5 changed files with 59 additions and 69 deletions

View File

@ -172,6 +172,12 @@ def get_type(field):
return "phone" return "phone"
elif field.fieldtype == "Data" and field.options == "Email": elif field.fieldtype == "Data" and field.options == "Email":
return "email" return "email"
elif field.fieldtype == "Check":
return "checkbox"
elif field.fieldtype == "Int":
return "number"
elif field.fieldtype in ["Small Text", "Text", "Long Text"]:
return "textarea"
elif field.read_only: elif field.read_only:
return "read_only" return "read_only"
return field.fieldtype.lower() return field.fieldtype.lower()

View File

@ -40,7 +40,7 @@
{ {
"fetch_from": "organization.annual_revenue", "fetch_from": "organization.annual_revenue",
"fieldname": "annual_revenue", "fieldname": "annual_revenue",
"fieldtype": "Int", "fieldtype": "Currency",
"label": "Amount", "label": "Amount",
"read_only": 1 "read_only": 1
}, },
@ -136,7 +136,7 @@
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2023-11-22 13:26:52.401192", "modified": "2023-11-22 17:52:31.595525",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "FCRM", "module": "FCRM",
"name": "CRM Deal", "name": "CRM Deal",

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="flex flex-col gap-1.5"> <div class="flex flex-col gap-1.5 max-h-[300px] overflow-y-auto">
<div <div
v-for="field in fields" v-for="field in fields"
:key="field.label" :key="field.label"
@ -8,15 +8,24 @@
<div class="w-[106px] shrink-0 text-gray-600"> <div class="w-[106px] shrink-0 text-gray-600">
{{ field.label }} {{ field.label }}
</div> </div>
<div class="flex-1 overflow-hidden"> <div class="grid flex-1 items-center overflow-hidden min-h-[28px]">
<Link <FormControl
v-if="field.type === 'link'" v-if="
[
'email',
'number',
'date',
'password',
'textarea',
'checkbox',
].includes(field.type)
"
class="form-control" class="form-control"
:type="field.type"
:value="data[field.name]" :value="data[field.name]"
:doctype="field.doctype"
:placeholder="field.placeholder" :placeholder="field.placeholder"
@change="(data) => emit('update', field.name, data)" :debounce="500"
:onCreate="field.create" @change.stop="emit('update', field.name, $event.target.value)"
/> />
<FormControl <FormControl
v-else-if="field.type === 'select'" v-else-if="field.type === 'select'"
@ -27,21 +36,14 @@
:debounce="500" :debounce="500"
@change.stop="emit('update', field.name, $event.target.value)" @change.stop="emit('update', field.name, $event.target.value)"
/> />
<FormControl <Link
v-else-if="field.type === 'email'" v-else-if="field.type === 'link'"
class="form-control" class="form-control"
type="email"
:value="data[field.name]" :value="data[field.name]"
:debounce="500" :doctype="field.doctype"
@change.stop="emit('update', field.name, $event.target.value)" :placeholder="field.placeholder"
/> @change="(data) => emit('update', field.name, data)"
<FormControl :onCreate="field.create"
v-else-if="field.type === 'date'"
class="form-control"
type="date"
:value="data[field.name]"
:debounce="500"
@change.stop="emit('update', field.name, $event.target.value)"
/> />
<Tooltip <Tooltip
v-else-if="field.type === 'read_only'" v-else-if="field.type === 'read_only'"
@ -86,3 +88,32 @@ const emit = defineEmits(['update'])
const data = defineModel() const data = defineModel()
</script> </script>
<style scoped>
:deep(.form-control input:not([type='checkbox'])),
:deep(.form-control select),
:deep(.form-control textarea),
:deep(.form-control button) {
border-color: transparent;
background: white;
}
:deep(.form-control button) {
gap: 0;
}
:deep(.form-control [type='checkbox']) {
margin-left: 9px;
cursor: pointer;
}
:deep(.form-control button > div) {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
:deep(.form-control button svg) {
color: white;
width: 0;
}
</style>

View File

@ -516,26 +516,3 @@ function updateField(name, value, callback) {
}) })
} }
</script> </script>
<style scoped>
:deep(.form-control input),
:deep(.form-control button) {
border-color: transparent;
background: white;
}
:deep(.form-control button) {
gap: 0;
}
:deep(.form-control button > div) {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
:deep(.form-control button svg) {
color: white;
width: 0;
}
</style>

View File

@ -357,27 +357,3 @@ function updateField(name, value, callback) {
}) })
} }
</script> </script>
<style scoped>
:deep(.form-control input),
:deep(.form-control select),
:deep(.form-control button) {
border-color: transparent;
background: white;
}
:deep(.form-control button) {
gap: 0;
}
:deep(.form-control button > div) {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
:deep(.form-control button svg) {
color: white;
width: 0;
}
</style>