2

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.

enter image description here

2 Answers 2

2

You can execute JavaScript on page load that will set contenteditable attribute to false for all text boxes.

$(".scWebEditInput").attr("contenteditable", false)
3
  • 1
    Probably want to target $("[scfieldtype='rich text']") rather than all editable fields.
    – jammykam
    Commented Aug 16, 2018 at 3:58
  • 1
    I 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 than false, I forcibly set it back to false. Commented Aug 17, 2018 at 11:10
0

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.