You are viewing limited content. For full access, please sign in.

Question

Question

rich text readonly

asked on August 30, 2019

Is there a way to make the rich text field read only with javascript?

0 0

Answer

SELECTED ANSWER
replied on September 3, 2019

In my examples I have given the rich-text field the custom css class name 'myRichText'.

 

To make this field non-editable, I used the following line.

$('.myRichText .cf-field > div > div').attr('contenteditable', 'false');

 

But to achieve results similar to setting the field as readonly on the designer, I used the following.

    // set border 0
    $('.myRichText .cf-field > div').addClass('noborder');

    // set attributes
    $('.myRichText .cf-field > div').attr({
        'autocomplete': 'off',
        'readonly': 'True',
        'backend-readonly': 'True'
    });

    // remove css
    $('.myRichText .cf-field > div').removeClass('panel');
    
    // set not editable
    $('.myRichText .cf-field > div > div').attr('contenteditable', 'false');

    // remove css
    $('.myRichText .cf-field > div > div').css('height', '');
    $('.myRichText .cf-field > div > div').removeClass('rich-text-editor');

    // remove editor-toolbar
    $('.myRichText .cf-field > div > div').remove('.editor-toolbar');

 

2 0
replied on September 3, 2019

That worked perfectly - Thank you!

0 0
replied on September 12, 2019

How would you remove the read only so that it will save the JS added value when Submit is clicked?

0 0
replied on September 16, 2019

It seems that as long as the element $('.myRichText .cf-field > div > div') has the class ('rich-text-editor'), it will save the values. You could add the class back to the element following a click event on the submit button.

 

Note that the field will expand out in height though, you may need to adjust the size with some CSS to suit your needs.

1 0
replied on September 16, 2019

Again, it worked perfectly - thank you so much Ray!

0 0
replied on February 1, 2023

Hi Ray.

I am trying to use your code to remove the editor toolbar on a rich text field and to make that field read only to the user. I have added the CSS class to the field "myRichText" and added the following css:

$('.myRichText .cf-field > div > div').remove('.editor-toolbar');
$('.myRichText .cf-field > div').attr({
    'autocomplete': 'off',
    'readonly': 'True',
  });

It has no affect on the behavior of the form and the rich text field is still editable, and the toolbar displays. I have entered your code incorrectly? 

Forms V11, on a "Modern Design" form. 

Thanks 

0 0
replied on August 23, 2023

Tim, did you ever get this working? Also interested in a read only rich text field without the editor.

0 0
replied on August 23, 2023

Yes we did using this code in the CSS section of the modern designed form. Note: It applies to all Rich Text fields on the form, not to a single field.  

.note-toolbar{
    display: none !important;
}

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.