Read_only and __islocal

Hello;

As I know that passing the “refresh” argument for frappe.ui.form.on means that we need to do some settings after saving the document, right?
If yes, then why we did not connect to the database using function(doc, cdt, cd) to be able to store the value of the read_only property of the field? Or where it will be saved?
The same thing regarding to the value of the property __islocal: where its value will be stored if it is not stored in the database?

frappe.ui.form.on(“MyDocType”, “refresh”, function(frm) {
// use the __islocal value of doc, to check if the doc is saved or not
frm.set_df_property(“myfield”, “read_only”, frm.doc.__islocal ? 0 : 1);
}

Regards
Bilal

1 Like

the second argument refresh is the trigger and the function will execute whenever the page, form is refreshed.

__local is just a flag it is not stored in the database, __local indicate that the document is new and not yet saved.

Thanks a lot for you makarad.

__local is just a flag it is not stored in the database, __local indicate that the document is new and not yet saved.

So, if we clicked on refresh to refresh the page and the document is new and not yet saved yet, then the read_only will stay 0 (so will not set the field to be read only). Right?

If the document is saved, so the refresh will happen after the save, right? In this case, how the read_only value will be saved in the database as we are setting it to value 1 after saving.

Regards
Bilal

yes

This method will check if the form is saved or not using __islocal if it is not saved then the field will be hidden after save however the field will be editable.

You can also use the frm.toggle_reqd(fieldname, true or false) to make field readonly and editable

1 Like

if __islocal is 1 then it is not saved and that means the field will be editable. You do not think so?

Regards
Bilal