Change background color for HTML field

ceraulo
Mega Guru

Hello!

 

I have a custom table which contains an HTML field. 

When the field is editable, the field looks like this:

ceraulo_0-1695279065359.png

 

When the field is set to read-only it looks like this:

ceraulo_1-1695279137380.png

Is it possible to set the background to gray similar to a text field as seen below:

ceraulo_2-1695279332722.png

 

Thank you.

10 REPLIES 10

rathan_now
Tera Contributor

Hi @ceraulo ,

Here is the Solution,
Write a On load Client script on the table,
Use this script 

function onLoad() {
  var fieldName = 'u_html_1'; // replace with your HTML field's name
  var control = g_form.getControl(fieldName);
  if (!control) return;

  // Wait until the TinyMCE editor is ready
  var interval = setInterval(function () {
    var editor = tinymce.get(control.id);
    if (editor && editor.getDoc && editor.getDoc().body) {
      editor.getDoc().body.style.backgroundColor = '#e0e0e0'; // your desired color
      clearInterval(interval);
    }
  }, 500);
}


and that it it works, change the colour accordingly in the code.

  • tinymce.get() accesses the TinyMCE instance for your HTML field.

  • editor.getDoc().body.style.backgroundColor directly modifies the iframe body.

  • A setInterval() waits until TinyMCE fully loads (since it's async).

    Mark it as helpful, if it solves your issue.
    Thanks,
    Rathan



 

Thanks for the response!
This works! but only one catch is that it does not load properly when we reload the page multiple times immediately. 

What is the business requirement here? There's no added value in writing scripts that can impact performance to make the field grayed out. This is technical debt and doesn't solve any problem. The field is not editable even if it's not grayed out, so I am not sure what your concern is.

Furthermore, even if you for some reason decide to go with the script that's proposed, which I'd never suggest doing, why would you reload the page multiple times? 

 

I agree with your perspective that this technical debt isn't necessary since the read-only functionality is already in place.

However, the end user is quite particular about the aesthetics. They find the varying colors for read-only fields on the same page to be inconsistent with the overall user experience.

Hristo Ivanov
Kilo Sage

 you can also try with applying default value to the field