Loop through all var fields in Catalog Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2014 09:48 AM
In a catalog client script I want to widen all of my reference fields, so I'm using code like this:
function onLoad() { var fields = ['STT_Opera_service', 'STT_Opera_component', 'STT_Opera_operations_lead', 'STT_Opera_opsTransitionLead']; for (var i = fields.length - 1; i >= 0; i--) { var varCon = g_form.getControl(fields[i]); var field = gel("sys_display."+ varCon.id); field.style.width = '350px'; } }
Is there a way to not hardcode those names, and instead just loop through all the fields defined on the form and just grab the ones of type Reference? The above works just fine...right up until I rename a variable, or delete one, or add a new one, or....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2014 10:06 AM
Using pure DOM methods:
var fields = document.getElementsByClassName('questionsetreference');
for (var i = fields.length - 1; i >= 0; i--) {
fields[i].style.width = '350px';
}
This works in Calgary. If you are using a different version you would need to get the class name of reference fields and replace 'questionsetreference' with your instance's reference field class name.
document.getElementsByClassName - Web API Interfaces | MDN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2014 10:38 AM
This is perfect, thank you!