Merge pull request #28660 from akurungadam/tab-ms-events

feat: add, before_remove and remove event triggers for Table MultiSelect
This commit is contained in:
Akhil Narang 2024-12-04 16:06:43 +05:30 committed by GitHub
commit a073984926
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 4 deletions

View file

@ -17,7 +17,7 @@ frappe.ui.form.on("Client Script", {
frappe.model.with_doctype(frm.doc.dt, () => {
const child_tables = frappe.meta
.get_docfields(frm.doc.dt, null, {
fieldtype: "Table",
fieldtype: ["in", ["Table", "Table MultiSelect"]],
})
.map((df) => df.options);

View file

@ -4,7 +4,6 @@ frappe.ui.form.ControlTableMultiSelect = class ControlTableMultiSelect extends (
static horizontal = false;
make_input() {
super.make_input();
this.$input_area.addClass("form-control table-multiselect");
this.$input.removeClass("form-control");
@ -29,9 +28,30 @@ frappe.ui.form.ControlTableMultiSelect = class ControlTableMultiSelect extends (
const value = decodeURIComponent($value.data().value);
const link_field = this.get_link_field();
this.rows = this.rows.filter((row) => row[link_field.fieldname] !== value);
this.rows = this.rows.filter((row) => {
if (row[link_field.fieldname] !== value) {
return row;
} else {
frappe.run_serially([
() => {
return this.frm.script_manager.trigger(
`before_${this.df.fieldname}_remove`,
this.df.options,
row.name
);
},
() => {
this.parse_validate_and_set_in_model("");
this.parse_validate_and_set_in_model("");
return this.frm.script_manager.trigger(
`${this.df.fieldname}_remove`,
this.df.options,
row.name
);
},
]);
}
});
});
this.$input_area.on("click", ".btn-link-to-form", (e) => {
const $target = $(e.currentTarget);
@ -68,6 +88,12 @@ frappe.ui.form.ControlTableMultiSelect = class ControlTableMultiSelect extends (
);
new_row[link_field.fieldname] = value;
this.rows = this.frm.doc[this.df.fieldname];
this.frm.script_manager.trigger(
`${this.df.fieldname}_add`,
this.df.options,
new_row.name
);
} else {
this.rows.push({
[link_field.fieldname]: value,