- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2016 06:22 AM
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2016 07:51 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2016 07:22 AM
UI Page usually display only read-only information. Isn't this the case for you?
Using Access Control Rules - ServiceNow Wiki
Regards,
Sergiu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2016 07:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2016 07:51 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2016 01:13 PM
Thanks - this worked perfectly. If anyone is curious, you can access the magnifying glass lookup element with 'lookup.fieldName'. So, in my case the code is:
gel('lookup.user_ws').style.display = "none";