Read-only and empty should not hide the field

Currently, read-only fields are hidden if they are empty. I can see why this feature might have seen sensible in the past, but I can’t think of any good reason why this should actually be the case now.

I have just had yet another email from an employee requesting that I make a field visible. That field is already visible, but it is read-only and (in many cases) meaningfully empty. Consequently, it disappears.

I would therefore request that ERPNext stops hiding read-only fields that are hidden.

If I wanted a field hidden, I would have made it hidden.
If I want to make it hidden when it is empty, this would be easy to do with depends_on.
By hiding fields like this you can mess up the layout.

Currently there is no easy way to stop ERPNext hiding the field when it is empty. The only ‘fixes’ are hacks like putting in a default value (but this is a date field, so what is a default value for a date), or making it only read-only client-side with a script, or removing the ‘hidden’ part with a script. This is all unnecessarily complicated and hard to maintain.

11 Likes

I had the same problem, I solved this problem by use custom script to frm.set_value(“name field readonly”, 0)
Hope this can help you.

This would be something to address in frappe not ERPNext.

+1 for this change request. I have some fields that can only be changed via custom dialogs, but I would still like them to be visible when they have no value.

1 Like

For still showing the read-only field when empty, you can set the field to data type and set the read-only parameter inside the field detail popup.

Hi Rahy, are you able to provide more detail on this solution?
I currently have this issue with fields I am setting as read-only … what exactly do you mean by the “field detail popup”?

Thanks, Dan

There are 2 ways to make a field read-only:

  • set the datatype as Read Only;
  • set the field type as anything (e.g. Data) and set the attribute to read-only.

To set the attribute, go to the field detail by clicking the field row. Scroll down until you find the checkboxes with label read-only.

Setting the datatype as Read only, totally hides the field. how should we make field name as visible and read only at the same time?

Use the second way.

Sorry to interrupt and revive this old thread, but I’m facing the same issue. I’m using the second way you described but still field is getting hidden. Any way I can do it without resorting to scripting?

Maybe just adding a css to display the field? I’ve never done this so I can’t be sure.

1 Like

@Adeel_Siddiqui Hey Adeel, don’t know if solved it or not, but adding a default value, any value, forces the field to show up. For me it was enough to set this to 0.

1 Like

Problem is, my field is a date field and will remain empty and is set by some logic on childtable, so I have to rely on scripts. Setting it from configuration only hides it altogether.

The following code in the Frappe framework base_control.js is the culprit:

if (
	this.doctype &&
	status === "Read" &&
	!this.only_input &&
	is_null(value) &&
	!in_list(["HTML", "Image", "Button", "Geolocation"], this.df.fieldtype)
) {
	if (explain) console.log("By Hide Read-only, null fields: None");
	status = "None";
}

In my case, we are able to simply remove these lines since we have our own fork of the Frappe framework. Sharing in case anyone happens to be in the same boat; or wishes to contribute to the Frappe framework to create an option to disable this behavior in the DocField settings.

4 Likes

+1 for this change request. It messes with the layout and is confusing to users when fields just disappear.

+1 for this change request

I connected to the database and assigned a value of 0 to the read only column in the relevant table. This solved the problem. Assigning a value of 0 as a default from the UI did not work.

Is any thing update from ERPNext side, without adding default data to database directly.