- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2014 09:37 AM
Hello All,
How do you modify the font color when the field is set to ReadOnly?
Out of the box, the background is grayed and the font is also grayed (slightly darker) when it's readOnly. I was asked to make the font color to black.
I appreciate your responses.
Thanks!
Dor
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2014 09:46 AM
This was my first assignment on ServiceNow, many years ago!
We have a global client script called "Fix Readonly Field Colors":
function onLoad(){
window.setTimeout(fix_readonly_field_colors,500);
}
function fix_readonly_field_colors() {
var i;
var the_inputs = document.getElementsByTagName('input');
for (i = 0; i < the_inputs.length; i++) {
if (the_inputs[i].disabled || the_inputs[i].readonly) {
the_inputs[i].style.color = '#000000';
the_inputs[i].style.backgroundColor = '#eeeeee';
}
}
the_inputs = document.getElementsByTagName('select');
for (i = 0; i < the_inputs.length; i++) {
if (the_inputs[i].disabled || the_inputs[i].readonly) {
the_inputs[i].style.color = '#000000';
the_inputs[i].style.backgroundColor = '#eeeeee';
}
}
the_inputs = document.getElementsByTagName('textarea');
for (i = 0; i < the_inputs.length; i++) {
if (the_inputs[i].disabled || the_inputs[i].readonly) {
the_inputs[i].style.color = '#000000';
the_inputs[i].style.backgroundColor = '#eeeeee';
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2014 10:15 AM
Looks like bianca.vaccarini will have to convert it to a question first.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2014 10:18 AM
This discussion has been switched to a question. You should now see the ability to mark a correct or helpful response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2014 10:20 AM
bianca.vaccarini you are the best!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2014 12:16 PM
I modified the function. Please see below...
function fix_readonly_field_colors() {
var elemArray = ['input', 'select', 'textarea'];
var i, j;
for (j = 0; j < elemArray.length; j++) {
var the_inputs = document.getElementsByTagName(elemArray[j]);
for (i = 0; i < the_inputs.length; i++) {
if (the_inputs[i].disabled || the_inputs[i].readonly) {
the_inputs[i].style.color = '#000000';
the_inputs[i].style.backgroundColor = '#FCFCFC';
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2014 10:24 AM
So here is the same function, now implemented in one line with jQuery!
function fix_readonly_field_colors() {
jQuery(".readonly, .disabled, :disabled").css("color","#000000").css("background-color","#eeeeee");
}
Cheers,
Geoff.