0

I am using Siteore 9.3 also using Glass mapper 5 and I have one Single-Line-Text and I am binding value just like mentioned below:

   <div class="heading-5 header-text">@Html.Glass().Editable(card, m => m.CardHeader)</div>

While I am updating value of Single-Line-Text from experience editor. It is adding extra P tag with text.

enter image description here

1

I checked the issue with the current Sitecore.NET 9.3.0 (rev. 003498) without a hotfix mentioned by @Ed Lane (@ed-lane), and with the hotfix installed. The behaviour still the same, the issue is not fixed, despite the fact that InlineEditingUtil.js was updated and contains a couple of improvements.

Only single-line text was checked & patched

The root cause: the P tag or DIV tag is added into empty input control, the tag depends on Sitecore setting

<setting name="HtmlEditor.LineBreak" value="p" />

How to simulate the issue

  1. empty any single-line text input control to get [No text in field] there
  2. add any text
  3. save the page
  4. P tag become visible, it was added into empty SPAN in this.checkEmptyEditableElement() method (or this.prepopulateEmptyElement() method in case of hotfix applied), see InlineEditingUtil.js for details

How to fix the issue - the original version

Open \sitecore\shell\Applications\Page Modes\InlineEditingUtil.js, this.checkEmptyEditableElement() method must be patched to avoid adding unwanted p tag into empty input:

this.checkEmptyEditableElement = function(target) {
...
    // start of patch - the condition added
    // to avoid adding unwanted p tag into empty single-line text input control
    if (target.getAttribute("scfieldtype") !== "single-line text") {
    // end of patch
        var node = document.createElement(newLineNode);
        range.insertNode(node);
        range.collapse(true);
        node.innerHTML = "<br />";
        range.selectNodeContents(node);

        selection.removeAllRanges();
        selection.addRange(range);
    // start of patch
    }
    // end of patch
...
};

How to fix the issue - version with hotfix

Open \sitecore\shell\Applications\Page Modes\InlineEditingUtil.js, this.prepopulateEmptyElement() and this.getClosestFieldNode() methods must be patched to avoid adding unwanted p tag into empty input:

this.prepopulateEmptyElement = function(target, fieldType) {
...
    } else
    // start of patch - the condition added
    // to avoid adding unwanted p tag into empty single-line text input control
    if (fieldType !== "single-line text")
    // end of patch
    {
        var newLineNode = Sitecore.WebEditSettings.newLineBreak;
        if (newLineNode.toLowerCase() == "p" || newLineNode.toLowerCase() == "div") {

            var node = document.createElement(newLineNode);
            range.insertNode(node);
            range.collapse(true);
            node.innerHTML = "<br />";
            range.selectNodeContents(node);

            selection.removeAllRanges();
            selection.addRange(range);
        }
    }
...
};

this.getClosestFieldNode = function(currentNode) {
    var result;

    // start of patch - to select valid sitecore container
    if (currentNode.nodeName == '#text')
    {
        currentNode = this.getClosestFieldNode(currentNode.parentElement);
    }
    // end of patch

    if (currentNode.getAttribute("scfieldtype") != null ||
        currentNode.tagName.localeCompare('body', 'en', { sensitivity: 'base' }) == 0) {
        result = currentNode;
    } else {
        result = this.getClosestFieldNode(currentNode.parentElement);
    }
    return result;
};

the code before the patch applied: enter image description here

0

We experienced the same issue with Multi-Line text.

Sitecore Support provided a Hotfix for this:

"As a quick test, could you please install the hotfix available at the following URL and check if it helps:

https://sitecore.box.com/s/nos0inc1v5dm6dzwau15mmgltnvdoplp

Be aware that the hotfix was built specifically for Sitecore 9.3.0 (Initial Release), and you should not install it on other Sitecore versions or in combination with other hotfixes, unless explicitly instructed by Sitecore Support.

Note that you need to extract ZIP file contents to locate installation instructions and related files inside it.

Unless stated differently in the installation instructions, the hotfix should be installed on CM instance and then synced with other instances using your regular development practices."

Hope this helps.

1
  • I checked the hotfix, but it seems to be the bug with <p> still there :( – Andriy B. Nov 26 '20 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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