feat(coupon-details): prevent duplicate course/batch selections and clear name on type change
This commit is contained in:
@@ -65,10 +65,12 @@
|
|||||||
{ label: 'Course ', value: 'LMS Course' },
|
{ label: 'Course ', value: 'LMS Course' },
|
||||||
{ label: 'Batch ', value: 'LMS Batch' },
|
{ label: 'Batch ', value: 'LMS Batch' },
|
||||||
]"
|
]"
|
||||||
|
@change="(val) => (row.reference_name = null)"
|
||||||
/>
|
/>
|
||||||
<Link
|
<Link
|
||||||
class="min-w-40"
|
class="min-w-40"
|
||||||
:doctype="row.reference_doctype || 'LMS Course'"
|
:doctype="row.reference_doctype || 'LMS Course'"
|
||||||
|
:filters="getFilters(idx)"
|
||||||
:label="__('Name')"
|
:label="__('Name')"
|
||||||
:value="row.reference_name"
|
:value="row.reference_name"
|
||||||
@change="(opt) => (row.reference_name = opt)"
|
@change="(opt) => (row.reference_name = opt)"
|
||||||
@@ -158,6 +160,22 @@ function removeRow(idx) {
|
|||||||
doc.value.applicable_items.splice(idx, 1)
|
doc.value.applicable_items.splice(idx, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFilters(idx) {
|
||||||
|
// don't show the batch or course that has already been selected
|
||||||
|
const row = doc.value.applicable_items[idx]
|
||||||
|
if (!row.reference_doctype) return {}
|
||||||
|
const doctype = row.reference_doctype
|
||||||
|
const selectedNames = doc.value.applicable_items
|
||||||
|
.filter(
|
||||||
|
(r, i) => i !== idx && r.reference_doctype === doctype && r.reference_name
|
||||||
|
)
|
||||||
|
.map((r) => r.reference_name)
|
||||||
|
if (selectedNames.length === 0) return {}
|
||||||
|
return {
|
||||||
|
name: ['not in', selectedNames],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const saveDoc = createResource({
|
const saveDoc = createResource({
|
||||||
url: 'frappe.client.save',
|
url: 'frappe.client.save',
|
||||||
makeParams(values) {
|
makeParams(values) {
|
||||||
|
|||||||
Reference in New Issue
Block a user