fix: implement mandatory depends on in settings page
This commit is contained in:
parent
3f85c56746
commit
3129c46a6f
@ -25,14 +25,14 @@
|
||||
"fieldname": "api_key",
|
||||
"fieldtype": "Data",
|
||||
"label": "API Key",
|
||||
"mandatory_depends_on": "eval:!doc.is_erpnext_in_different_site"
|
||||
"mandatory_depends_on": "is_erpnext_in_different_site"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.enabled && doc.is_erpnext_in_different_site",
|
||||
"fieldname": "api_secret",
|
||||
"fieldtype": "Data",
|
||||
"label": "API Secret",
|
||||
"mandatory_depends_on": "eval:!doc.is_erpnext_in_different_site"
|
||||
"mandatory_depends_on": "is_erpnext_in_different_site"
|
||||
},
|
||||
{
|
||||
"depends_on": "enabled",
|
||||
@ -48,7 +48,7 @@
|
||||
"fieldname": "erpnext_site_url",
|
||||
"fieldtype": "Data",
|
||||
"label": "ERPNext Site URL",
|
||||
"mandatory_depends_on": "eval:!doc.is_erpnext_in_different_site"
|
||||
"mandatory_depends_on": "is_erpnext_in_different_site"
|
||||
},
|
||||
{
|
||||
"depends_on": "enabled",
|
||||
@ -94,13 +94,14 @@
|
||||
"fieldname": "deal_status",
|
||||
"fieldtype": "Link",
|
||||
"label": "Deal Status",
|
||||
"mandatory_depends_on": "create_customer_on_status_change",
|
||||
"options": "CRM Deal Status"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2024-09-16 20:51:17.148493",
|
||||
"modified": "2024-09-16 21:30:40.097360",
|
||||
"modified_by": "Administrator",
|
||||
"module": "FCRM",
|
||||
"name": "ERPNext CRM Settings",
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
(field.read_only && data[field.name]) ||
|
||||
!field.read_only ||
|
||||
!field.hidden) &&
|
||||
(!field.depends_on || field.display_depends_on)
|
||||
(!field.depends_on || field.display_via_depends_on)
|
||||
"
|
||||
>
|
||||
<div
|
||||
@ -36,7 +36,14 @@
|
||||
class="mb-2 text-sm text-gray-600"
|
||||
>
|
||||
{{ __(field.label) }}
|
||||
<span class="text-red-500" v-if="field.mandatory">*</span>
|
||||
<span
|
||||
class="text-red-500"
|
||||
v-if="
|
||||
field.mandatory ||
|
||||
(field.mandatory_depends_on && field.mandatory_via_depends_on)
|
||||
"
|
||||
>*</span
|
||||
>
|
||||
</div>
|
||||
<FormControl
|
||||
v-if="field.read_only && field.type !== 'Check'"
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
:sections="sections"
|
||||
:data="data.doc"
|
||||
/>
|
||||
<ErrorMessage class="mt-2" :message="error" />
|
||||
</div>
|
||||
<div v-else class="flex flex-1 items-center justify-center">
|
||||
<Spinner class="size-8" />
|
||||
@ -36,9 +37,10 @@ import {
|
||||
createResource,
|
||||
Spinner,
|
||||
Badge,
|
||||
ErrorMessage,
|
||||
} from 'frappe-ui'
|
||||
import { evaluate_depends_on_value, createToast } from '@/utils'
|
||||
import { computed } from 'vue'
|
||||
import { ref, computed } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
doctype: {
|
||||
@ -65,6 +67,8 @@ const fields = createResource({
|
||||
auto: true,
|
||||
})
|
||||
|
||||
const error = ref(null)
|
||||
|
||||
const data = createDocumentResource({
|
||||
doctype: props.doctype,
|
||||
name: props.doctype,
|
||||
@ -73,6 +77,7 @@ const data = createDocumentResource({
|
||||
auto: true,
|
||||
setValue: {
|
||||
onSuccess: () => {
|
||||
error.value = null
|
||||
createToast({
|
||||
title: __('Success'),
|
||||
text: __(props.successMessage),
|
||||
@ -117,10 +122,14 @@ const sections = computed(() => {
|
||||
} else {
|
||||
_sections[_sections.length - 1].fields.push({
|
||||
...field,
|
||||
display_depends_on: evaluate_depends_on_value(
|
||||
display_via_depends_on: evaluate_depends_on_value(
|
||||
field.depends_on,
|
||||
data.doc,
|
||||
),
|
||||
mandatory_via_depends_on: evaluate_depends_on_value(
|
||||
field.mandatory_depends_on,
|
||||
data.doc,
|
||||
),
|
||||
name: field.value,
|
||||
})
|
||||
}
|
||||
@ -130,6 +139,24 @@ const sections = computed(() => {
|
||||
})
|
||||
|
||||
function update() {
|
||||
error.value = null
|
||||
if (validateMandatoryFields()) return
|
||||
data.save.submit()
|
||||
}
|
||||
|
||||
function validateMandatoryFields() {
|
||||
for (let section of sections.value) {
|
||||
for (let field of section.fields) {
|
||||
if (
|
||||
(field.mandatory ||
|
||||
(field.mandatory_depends_on && field.mandatory_via_depends_on)) &&
|
||||
!data.doc[field.name]
|
||||
) {
|
||||
error.value = __('{0} is mandatory', [__(field.label)])
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
</script>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user