How to make a field readonly?

Hi all,

I am wondering how to make a field readonly. I am looking for a rule for this purpose but I don’t see it. As you see in the image below we have the option to “Make field mandatory”.

image

Like this, how can I make a field readonly so the user cannot edit it?

Kindly assist.

1 Like

Hi @MSP,
From my understanding, I think Read Only would imply that the field should not be editable by the user because, let’s say it’s a pre-populated field; whereas Mandatory would mean that the user MUST enter data into the field or rather it is a required field not to be skipped;

From the User Manual;

If you want it to be mandatory to fill all values for a data element in data entry if one or more values have been filled, select All fields for data elements required .

This means that if you enter one data value for a data element in an entry field (that is for a category option combination), then you must enter data for all fields belonging to that data element (that is all category option combinations).

Let me know if this helps.

Best,
James.

Hi @jomutsani,

Thanks for your reply and yes, your understanding is correct. But my requirement is to set a field as Readonly.

The data for this field will be populated through a db script and not using a program rule. So once populated, I want the user to view only, not allowing him to make any changes. Any idea how can I achieve this?

Please note, I am using Tracker.

1 Like

Hi @MSP,
I do work with web api. I was searching with same issue you faced but found no answer.
I have solved the issue by creating a Program Rule with action ‘Assign value’.

Just create a Program rule variable with the data element you need to make readonly.
Create Program rule and provide rule expression something always true (I have given 1 == 1).
Choose Program rule action as ‘Assign value’.
Set ‘Data element to assign to’ with your same data element.
Set ‘Expression to evaluate and assign’ with your created program rule variable.

I have tested it in 2.29 version in Event program. It also do the same in Tracker.

2 Likes

Thank you @nabiullah for taking time to research and provide a solution/workaround.

I will test and update here.

1 Like