fix: show discard dialog only if form is dirty
This commit is contained in:
parent
364366ae99
commit
b1944916c3
1 changed files with 21 additions and 11 deletions
|
|
@ -166,20 +166,30 @@ export default class WebForm extends frappe.ui.FieldGroup {
|
|||
}
|
||||
|
||||
setup_discard_action() {
|
||||
$(".web-form-footer .discard-btn").on("click", () => this.discard_form());
|
||||
$(".web-form-footer .discard-btn").on("click", (e) => {
|
||||
setTimeout(() => {
|
||||
e.stopPropagation();
|
||||
this.discard_form();
|
||||
}, 200);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
discard_form() {
|
||||
frappe.warn(
|
||||
__("Discard?"),
|
||||
__("Are you sure you want to discard the changes?"),
|
||||
() => {
|
||||
let path = window.location.href;
|
||||
// remove new or edit after last / from url
|
||||
window.location.href = path.substring(0, path.lastIndexOf("/"));
|
||||
},
|
||||
__("Discard")
|
||||
);
|
||||
let path = window.location.href;
|
||||
// remove new or edit after last / from url
|
||||
path = path.substring(0, path.lastIndexOf("/"));
|
||||
|
||||
if (frappe.form_dirty) {
|
||||
frappe.warn(
|
||||
__("Discard?"),
|
||||
__("Are you sure you want to discard the changes?"),
|
||||
() => (window.location.href = path),
|
||||
__("Discard")
|
||||
);
|
||||
} else {
|
||||
window.location.href = path;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue