How to make entire form read-only after saving

Hi There,

We have setup a new doctype called ‘Compliance Record’. It has few fields like employee, compliance type, compliance text and acknowledgement date (mandatory field) . Each employee needs to acknowledge this compliance form once a year by entering acknowledgement date. Few questions:

  • How do we make entire form read-only once an employee has selected acknowledgement date and clicked on Save. We want to do this because once the employee had acknowledge the form we don’t want them to change anything.

Currently I am hiding the save button to tackle the above using below script. We also wants each field to be read-only and do this by making the entire form read-only rather setting each field to read-only in the code.

frappe.ui.form.on("Compliance Record", {
    refresh: function(frm) {
        if (!frm.is_new()) {
            frm.disable_save();
        }
    }
});
  • How do make sure that they don’t fill another form for the same year? should we use validate method on the server side to validate this?

Thanks.

2 Likes

I just realised that the above script is not working every time. So need help with that as well. It work for existing form and if then go and click on new then the save button is not visible.

As far as making it read only, why not just make it a submittable form?

4 Likes

To make all the fields read-only i use

cur_frm.fields.forEach(function(l){ cur_frm.set_df_property(l.wrapper.title, “read_only”, 1); })
put all fields read_only. VERSION 4

cur_frm.fields.forEach(function(l){ cur_frm.set_df_property(l.df.fieldname, “read_only”, 1); })
put all fields VERSION 5

Yes, you need to check this on validate method.

4 Likes

@geekroot how to disable particular doctype while filling data in other doctype.say for ex there are 3 doctypes A,B,C and based on selection of doctype in c doctype i have to make that doctype read only.

any updates?