How can I disable inline editing of rich text fields in Experience Editor? I still want the users to be able to click the edit icon in the toolbar popup (leftmost icon in the attached screenshot) so that they can go to the full editor, but I don't want them to be able to insert text directly onto the page.
2 Answers
You can execute JavaScript on page load that will set contenteditable attribute to false for all text boxes.
$(".scWebEditInput").attr("contenteditable", false)
-
1Probably want to target
$("[scfieldtype='rich text']")
rather than all editable fields.– jammykamCommented Aug 16, 2018 at 3:58 -
1I put this in document.ready but it didn't change the
contenteditable
attribute. This is probably because Experience Editor adds the content and functionality after the document is ready, so that when I add my modification, it is overwritten by Experience Editor later. Do you have any tips on which other events I can do this on to not have it overwritten by Experience Editor later? Commented Aug 16, 2018 at 10:51 -
I ended up using a MutationObserver in my JS to listen for changes to the
contenteditable
attribute on the$("[scfieldtype='rich text']")
elements. Whenever it is changed to something other thanfalse
, I forcibly set it back tofalse
. Commented Aug 17, 2018 at 11:10
If you have access to the bool
value you want to use to toggle editability during rendering time, you can also do it by passing in the DisableEditable
parameter to the Editable()
method like so:
// Set this variable to false to disable the editability in Experience Editor
bool shouldBeEditable = false;
@Html.Glass().Editable(Model, x => x.Title, shouldBeEditable ? "DisableEditable=true" : null)