Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added mandatory depends for custom fields to conditionally make fields mandatory #1744

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions desk/src/pages/ticket/TicketNew.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
v-for="field in visibleFields"
:key="field.fieldname"
:field="field"
:value="templateFields[field.fieldname]"
@change="templateFields[field.fieldname] = $event.value"
:value="doc[field.fieldname]"
@change="handleChange(field.fieldname, $event.value)"
/>
</div>
<div class="m-5">
Expand Down Expand Up @@ -71,13 +71,20 @@ const router = useRouter();
const subject = ref("");
const description = ref("");
const attachments = ref([]);
const templateFields = reactive({});
const doc = reactive({});
let fieldMandateMappings = {};

const template = createResource({
url: "helpdesk.helpdesk.doctype.hd_ticket_template.api.get_one",
makeParams: () => ({
name: props.templateId || "Default",
}),
onSuccess: (data) => {
data.fields?.forEach((f) => {
if (f.mandatory_depends_on)
fieldMandateMappings[f.fieldname] = f.mandatory_depends_on;
});
},
auto: true,
});

Expand All @@ -94,7 +101,7 @@ const ticket = createResource({
description: description.value,
subject: subject.value,
template: props.templateId,
...templateFields,
...doc,
},
attachments: attachments.value,
}),
Expand Down Expand Up @@ -124,6 +131,19 @@ function sanitize(html: string) {
});
}

function handleChange(fieldname, value) {
doc[fieldname] = value;
Object.keys(fieldMandateMappings).forEach((mField) => {
if (eval(fieldMandateMappings[mField])) {
let v = visibleFields.value.find((vf) => vf.fieldname === mField);
if (v) v.required = 1;
} else {
let v = visibleFields.value.find((vf) => vf.fieldname === mField);
if (v) v.required = 0;
}
});
}

usePageMeta(() => ({
title: "New Ticket",
}));
Expand Down
1 change: 1 addition & 0 deletions helpdesk/helpdesk/doctype/hd_ticket_template/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def get_fields(template: str, fetch: Literal["Custom Field", "DocField"]):
fields.hide_from_customer,
fields.required,
fields.url_method,
fields.mandatory_depends_on,
)
.join(QBFetch, JoinType.inner)
.on(QBFetch.fieldname == fields.fieldname)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"fieldname",
"url_method",
"required",
"hide_from_customer"
"hide_from_customer",
"placeholder",
"mandatory_depends_on"
],
"fields": [
{
Expand Down Expand Up @@ -38,12 +40,22 @@
"fieldtype": "Data",
"in_list_view": 1,
"label": "URL/Method"
},
{
"fieldname": "placeholder",
"fieldtype": "Data",
"label": "Placeholder"
},
{
"fieldname": "mandatory_depends_on",
"fieldtype": "Data",
"label": "Mandatory Depends On"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-08-04 15:42:36.143195",
"modified": "2024-04-05 13:42:28.270761",
"modified_by": "Administrator",
"module": "Helpdesk",
"name": "HD Ticket Template Field",
Expand Down
Loading