Is there a way to hide the HTML field editor toolbar on just one form?

bnine
Kilo Contributor

I know that you can go into System Properties > UI Properties and edit the 'Configures the editing toolbar' sections to choose what show up, but it looks like this will affect other parts of the system instead of just the app I am working in.

We only want to remove it on one form for now. Right now I have this HTML field being populated with the contents of the KB article being attached to the ticket, and we are going to be sending the contents of the field to the caller in an email, and we want the user to be able to see what it will look like. (I had used the regex .replace() scripts floating around here remove the HTML tags that came up when the KB contents were copied into a regular string field in plain text, but that was inadequate). I think this is the

Is there a way to do this, maybe with a client script?

find_real_file.png

P.S. I have just over a month's worth of experience with ServiceNow, so let me know if I am posting this in the wrong place or something

1 ACCEPTED SOLUTION

ahaz86
Mega Guru

First thing that comes to mind is an on load client script.



function onLoad() {


  var sheet = window.document.styleSheets[0];


  sheet.insertRule('.mce-toolbar-grp { display: none !important; }', sheet.cssRules.length);


  sheet.addRule('.mce-toolbar-grp ', 'display: none !important;', -1); // IE likes to be different


}




Give that a shot


View solution in original post

25 REPLIES 25

that would also target the other elements. If trying to hide a specific element only once it is nice if there is an ID that you can work off of (that doesnt change). if you   were attempting to target an elements ID your code would look like this



sheet.insertRule('#myElementID { display: none !important; }', sheet.cssRules.length);  


Hi ahaz86,

     I am having the same issue. I used the code which did remove the formatting toolbar on the backend but not on the Catalog form itself. We are using the Service Portal. This all started because I was trying to get an image on a form but it wasn't working.

Can you provide any further assistance on removing the formatting toolbar for the catalog form (Service Portal) and also removing any additional white space.

Thank you,

Karen

 

I have an HTML field on our Incident table.  I was able to create an onLoad Client Script that simply looks like this:

var counter = 0;
var found = [];
found.push({
    "toolbar":false,
    "statusbar":false
});

function onLoad()
{
    setTimeout(function(){
        var i = 0, elements;

        //var varsForm = document.getElementsByClassName('veditor_body')[0];
        if (document)
        {
            // Hide the mce toolbar
            elements = document.getElementsByTagName('div');
            for (i = 0; i < elements.length; i++)
            {
                if (elements[i].className.indexOf('mce-toolbar') >= 0)
                {
                    elements[i].style.display = "none";
                    found[0].toolbar = true;
                }
                if (elements[i].className.indexOf('mce-statusbar') >= 0)
                {
                    elements[i].style.display = "none";
                    found[0].statusbar = true;
                }
            }
        }
        foundCheck();
    }, 100);
}


function foundCheck()
{
    /*
        At this point, we know that there is an active HTML field on the form.
        If onLoad() didn't find it, this means the DOM hasn't fully loaded yet,
        so we will re-call onLoad()
    */

    console.info("counter: " + counter);
    if (!found[0].toolbar || !found[0].statusbar)
    {
        // Safety check to stop any infinite loop possibility.
        // Since we're calling the timeout every 100 milliseconds,
        // this will stop trying after 5 seconds.
        if (counter++ >= 50)
        {
            return;
        }
        else
            onLoad();
    }
}

hi @ahaz86 this is not working for catalog item. Is there any other way for that ?

obedpaz99
Tera Contributor

Awesome, that was useful, thank you!