I don't want to apply styles to read-only fields

bonsai
Mega Sage

I edited the style of the field and gave it color.
However, I want the color to be gray if it is read-only as a requirement.

Styles now take precedence even if read-only.
Is there a way to reject a style if it is read-only?

8 REPLIES 8

Tai Vu
Kilo Patron
Kilo Patron

Hi @bonsai 

You may need a client script to identify whether or not a field is Readonly, then set the style of the field accordingly.

Sample below with OnLoad Client Script on 2 different fields Priority and Impact

function onLoad() {
    if (g_form.isDisabled('priority') != true) {
        var ctrPriority = g_form.getControl('priority');
        ctrPriority.style.backgroundColor = 'red';
    }

	if (g_form.isDisabled('impact') != true) {
        var ctrImpact = g_form.getControl('impact');
        ctrImpact.style.backgroundColor = 'red';
    }

}

Screenshot 2024-01-23 at 16.35.21.png

 

Cheers,

Tai Vu 

An error occurred when executing "ctrPriority.style.backgroundColor".
Reference and list fields are no longer available. . .

I noticed that I got an error because I tried to implement it with a UI policy.
However, this script did not color fields of reference type, list type, or True/False type.

Hi @bonsai 

For the Reference field type, you can try this below.

g_form.getControl('sys_display.<table_name>.<field_name>');

 

Can you share what kind of style you'd like to set for the List and True/False field types?

 

Cheers,

Tai Vu