Actually I have implemented a code to disable auto save when upload is done. then when I try to save the form by clicking save button, Save button will go to disabled version and form will not get saved.
Below is the code for stop saving when upload is clicked and it is working. Issue is after that save is not working
The code is :
let uploadInProgress = false;
frappe.ui.form.on(‘Auto save’, {
refresh: function(frm) {
setup_custom_file_upload(frm, ‘upload_image’);
setup_custom_file_upload(frm, ‘upload_technical_sheet’);
// Add event listener to the save button
frm.page.btn_primary.on('click', function() {
// Trigger form save directly when save button is clicked
frappe.ui.form.save(frm);
});
}
});
function setup_custom_file_upload(frm, fieldname) {
let field = frm.fields_dict[fieldname];
if (!field) return;
field.$wrapper.on('change', 'input[type="file"]', function(e) {
e.stopImmediatePropagation();
e.preventDefault();
uploadInProgress = true;
let file_input = this;
let file = file_input.files[0];
if (!file) {
uploadInProgress = false;
return;
}
let form_data = new FormData();
form_data.append('file', file, file.name);
form_data.append('is_private', 1);
frappe.upload.upload_file(form_data, {
callback: function(file_url) {
frm.doc[fieldname] = file_url;
frm.refresh_field(fieldname);
uploadInProgress = false;
// Disable auto save after successful file upload
frm.disable_save();
}
});
});
}
frappe.ui.form.on(‘Auto save’, {
before_upload: function(frm) {
// Disable the save button when upload is clicked
frm.page.get_primary_btn().attr(‘disabled’, true);
}
});
frappe.ui.form.save = function(frm) {
// Trigger default form save behavior
return true;
};
This is the element I am getting once I click save button
<button class=“btn btn-primary btn-sm primary-action” data-label=“Save” disabled=“”>Save
Any solutions for it?