Is there a way to set a field to read-only on a UI Page?

andrew_lawlor
Giga Expert

So, I have a UI Page with a <g:ui_form> and a single <g:ui_reference> field. What's the best way to set such a field to read-only? I've tried the readonly HTML attribute to no avail.

Thank you!

1 ACCEPTED SOLUTION

ChrisBurks
Mega Sage

For <g:ui_form>, that element doesn't take the read-only attribute as it doesn't directly take any input. However, it contains input elements that will take input from the user but those have to be set individually and not through the form element.



For <g:ui_reference>, one way you can set this to read-only is by passing it a name which when rendered will produce an id for the element more than likely with a "sys_display." prepended to the name you gave it.


From there, either in the html/xml field of the UI page or in the client script field create a script that will grab the element and set it to read-only.


For example:



HTML/XML:


<g:ui_reference name="my_ref" table="sys_user" />



Client Script:


var ro = gel('sys_display.my_ref');


ro.readOnly = true;




Note: Doing this will make the input field itself read-only. It won't stop the user from using the lookup icon to select a record. For that you may have to hide the lookup icon, remove the function on the onclick attribute, or other method.


View solution in original post

5 REPLIES 5

Is this possible to make read only the reference field in ui page on load?


Thanks,
Abdul Fathah
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.