Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitecore rich text field in page editor is not editable when it contains HTML formatting

I have a number of fields that are editable in Page Editor. One of them is a rich text field. This is the html:

@foreach (var speaker in Model.Speakers)
{
    <div class="speaker__item" id="@speaker.Id">
        <div class="speaker__media">
            @RenderImage(speaker, x => x.Speaker_Image, isEditable: true)
        </div>
        <div class="speaker__info">
            @if (IsInEditingMode || !string.IsNullOrEmpty(speaker.Speaker_Name))
            {
                <h4 class="speaker__name">@Editable(speaker, x => x.Speaker_Name)</h4>
            }

            @if (IsInEditingMode || !string.IsNullOrEmpty(speaker.Speaker_Title))
            {
                <p class="speaker__title">@Editable(speaker, x => x.Speaker_Title)</p>
            }

            @if (IsInEditingMode || !string.IsNullOrEmpty(speaker.Speaker_Description))
            {
                <div class="speaker__bio">
                    <p>@Editable(speaker, x => x.Speaker_Description)</p>
                </div>
            }

            @RenderLink(speaker, x => x.Speaker_Bio, attributes: new { @class = "speaker__link" }, isEditable: true)
        </div>
    </div>
}

The rich text field is Speaker_Description. When there is no HTML in the field (i.e. just plain text), it renders correctly and is editable in page editor. When the field does contain html, such as being wrapped in a <p> tag or including line breaks, it renders correctly, but is not editable on the page. I can still edit the field in Sitecore, but the area is unclickable in Page Editor.

like image 660
Erica Stockwell-Alpert Avatar asked Mar 08 '23 07:03

Erica Stockwell-Alpert


1 Answers

This is a known issue when you put an editable rich text inside a <p> tag.

There are plenty of html tags which are not allowed inside a <p> tag. That why your browser closes <p> tag and break the functionality of editable rich text.

Remove <p> tag which is around the @Editable.

like image 116
Marek Musielak Avatar answered May 26 '23 07:05

Marek Musielak