clear contact details when switching from existing to new contact

- Ensure previously selected contact details are removed when toggling  
- Clear all fields in the 'contact_details_section' when choosing an existing contact  
- Set 'contact' field to null when switching to a new contact  
- Prevents unnecessary data from being sent to the API
This commit is contained in:
Muhammed Raihan P A 2025-02-19 01:22:54 -08:00 committed by GitHub
parent 7101fadd36
commit cf43935508
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -190,6 +190,24 @@ function createDeal() {
if (deal.website && !deal.website.startsWith('http')) {
deal.website = 'https://' + deal.website
}
if (chooseExistingContact.value) {
const contactDetailsFields = new Set(
tabs.data.flatMap((tab) =>
tab.sections
.filter((section) => section.name === 'contact_details_section')
.flatMap((section) =>
section.columns.flatMap((column) =>
column.fields.map((field) => field.fieldname),
),
),
),
)
contactDetailsFields.forEach((field) => {
deal[field] = null
})
} else deal['contact'] = null
createResource({
url: 'crm.fcrm.doctype.crm_deal.crm_deal.create_deal',
params: { args: deal },