fix: implemented add fields using autocomplete
This commit is contained in:
parent
2f4acd7b13
commit
a1eb3a6dd4
@ -431,17 +431,24 @@ def get_list_data(
|
|||||||
"list_script": get_form_script(doctype, "List"),
|
"list_script": get_form_script(doctype, "List"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
def get_fields_meta(doctype):
|
def get_fields_meta(doctype, restricted_fieldtypes=None, as_array=False):
|
||||||
not_allowed_fieldtypes = [
|
not_allowed_fieldtypes = [
|
||||||
"Tab Break",
|
"Tab Break",
|
||||||
"Section Break",
|
"Section Break",
|
||||||
"Column Break",
|
"Column Break",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if restricted_fieldtypes:
|
||||||
|
restricted_fieldtypes = frappe.parse_json(restricted_fieldtypes)
|
||||||
|
not_allowed_fieldtypes += restricted_fieldtypes
|
||||||
|
|
||||||
fields = frappe.get_meta(doctype).fields
|
fields = frappe.get_meta(doctype).fields
|
||||||
fields = [field for field in fields if field.fieldtype not in not_allowed_fieldtypes]
|
fields = [field for field in fields if field.fieldtype not in not_allowed_fieldtypes]
|
||||||
|
|
||||||
|
if as_array:
|
||||||
|
return fields
|
||||||
|
|
||||||
fields_meta = {}
|
fields_meta = {}
|
||||||
for field in fields:
|
for field in fields:
|
||||||
fields_meta[field.fieldname] = field
|
fields_meta[field.fieldname] = field
|
||||||
|
|||||||
@ -38,7 +38,7 @@
|
|||||||
class="flex flex-1 flex-col justify-between overflow-hidden"
|
class="flex flex-1 flex-col justify-between overflow-hidden"
|
||||||
>
|
>
|
||||||
<div class="flex flex-col overflow-y-auto">
|
<div class="flex flex-col overflow-y-auto">
|
||||||
<SidebarLayoutBuilder :sections="sections.data" />
|
<SidebarLayoutBuilder :sections="sections.data" :doctype="doctype" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Resizer>
|
</Resizer>
|
||||||
@ -75,7 +75,7 @@ function saveChanges() {
|
|||||||
let _sections = JSON.parse(JSON.stringify(sections.data))
|
let _sections = JSON.parse(JSON.stringify(sections.data))
|
||||||
_sections.forEach((section) => {
|
_sections.forEach((section) => {
|
||||||
if (!section.fields) return
|
if (!section.fields) return
|
||||||
section.fields = section.fields.map((field) => field.name)
|
section.fields = section.fields.map((field) => field.fieldname || field.name)
|
||||||
})
|
})
|
||||||
loading.value = true
|
loading.value = true
|
||||||
call('crm.api.doc.save_fields_layout', {
|
call('crm.api.doc.save_fields_layout', {
|
||||||
|
|||||||
@ -66,13 +66,33 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</Draggable>
|
</Draggable>
|
||||||
<Button
|
<Autocomplete
|
||||||
v-if="section.editable !== false"
|
v-if="fields.data && section.editable !== false"
|
||||||
class="w-full mt-2"
|
value=""
|
||||||
variant="outline"
|
:options="fields.data"
|
||||||
:label="__('Add Field')"
|
@change="(e) => addField(section, e)"
|
||||||
@click="section.fields.push({ label: 'New Field' })"
|
>
|
||||||
/>
|
<template #target="{ togglePopover }">
|
||||||
|
<Button
|
||||||
|
class="w-full mt-2"
|
||||||
|
variant="outline"
|
||||||
|
@click="togglePopover()"
|
||||||
|
:label="__('Add Field')"
|
||||||
|
>
|
||||||
|
<template #prefix>
|
||||||
|
<FeatherIcon name="plus" class="h-4" />
|
||||||
|
</template>
|
||||||
|
</Button>
|
||||||
|
</template>
|
||||||
|
<template #item-label="{ option }">
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<div>{{ option.label }}</div>
|
||||||
|
<div class="text-gray-500 text-sm">
|
||||||
|
{{ `${option.fieldname} - ${option.fieldtype}` }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</Autocomplete>
|
||||||
<div
|
<div
|
||||||
v-else
|
v-else
|
||||||
class="flex justify-center items-center border rounded border-dashed p-3"
|
class="flex justify-center items-center border rounded border-dashed p-3"
|
||||||
@ -98,11 +118,49 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import Autocomplete from '@/components/frappe-ui/Autocomplete.vue'
|
||||||
import DragVerticalIcon from '@/components/Icons/DragVerticalIcon.vue'
|
import DragVerticalIcon from '@/components/Icons/DragVerticalIcon.vue'
|
||||||
import Draggable from 'vuedraggable'
|
import Draggable from 'vuedraggable'
|
||||||
import { Input } from 'frappe-ui'
|
import { Input, createResource } from 'frappe-ui'
|
||||||
|
import { computed, watch } from 'vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
sections: Object,
|
sections: Object,
|
||||||
|
doctype: String,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const restrictedFieldTypes = [
|
||||||
|
'Table',
|
||||||
|
'Geolocation',
|
||||||
|
'Attach',
|
||||||
|
'Attach Image',
|
||||||
|
'HTML',
|
||||||
|
'Signature',
|
||||||
|
]
|
||||||
|
|
||||||
|
const params = computed(() => {
|
||||||
|
return {
|
||||||
|
doctype: props.doctype,
|
||||||
|
restricted_fieldtypes: restrictedFieldTypes,
|
||||||
|
as_array: true,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const fields = createResource({
|
||||||
|
url: 'crm.api.doc.get_fields_meta',
|
||||||
|
params: params.value,
|
||||||
|
cache: ['fieldsMeta', props.doctype],
|
||||||
|
auto: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
function addField(section, field) {
|
||||||
|
if (!field) return
|
||||||
|
section.fields.push(field)
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.doctype,
|
||||||
|
() => fields.fetch(params.value),
|
||||||
|
{ immediate: true },
|
||||||
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user