Introduction
Welcome to this Empress guide where we’ll walk you through the “Make Read Only After Saving” feature. This handy tool enables you to update a field’s visibility within a document type, allowing you to make a field read-only after a document has been saved. This is particularly useful for business users who want to prevent further changes to a document after it has been saved.
Understanding “Make Read Only After Saving”
“Make Read Only After Saving” is a feature in Empress designed to help you control the editability of your form fields. In a practical sense, this means that once a document has been saved, certain fields can be made read-only, preventing further changes and maintaining the integrity of the information.
How it Works
Every document type in Empress has a property known as __islocal
. This property tells you whether a document has been saved at least once or never been saved. If __islocal
is 1
, it means the document hasn’t been saved yet.
To change the read-only property of a field based on whether the document is new or saved, Empress uses a method called cur_frm.set_df_property
.
Step-by-Step Guide
Here’s how you can use the cur_frm.set_df_property
method:
-
Access The Refresh Event of the Form: The
cur_frm.set_df_property
method is used within the refresh event of the form. This ensures that the read-only property of your chosen field is updated every time the form is refreshed. -
Determine If The Document Is New or Saved: Empress uses a method called
frm.is_new()
to check if the document has been saved. If the document is new (i.e., unsaved), theis_new()
method returns1
, making the field editable. However, if the document is not new (i.e., saved at least once), theis_new()
method returns0
, making the field read-only.
Here’s what the script might look like:
frappe.ui.form.on("MyDocType", "refresh", function(frm) {
frm.set_df_property("myfield", "read_only", frm.is_new() ? 0 : 1);
}
In this script, “myfield” is the name of the field you want to make read-only after saving the document.
The Benefits
By using the “Make Read Only After Saving” feature, you can:
- Enhance Usability: Create more interactive and user-friendly forms.
- Maintain Data Integrity: Prevent further changes to a document after it has been saved.
- Improve Workflow Efficiency: Streamline data entry and document management processes.
By understanding and effectively using properties and methods like __islocal
, cur_frm.set_df_property
, and frm.is_new()
, you can significantly enhance the usability and functionality of your Empress applications.
For additional support or resources on how to make the most of Empress, please visit our non-technical help center or contact our customer support team. Happy Empressing!