Search code examples
tridiontridion-2011

Deleting all text from a text box leaves behind a <br> tag


I am using Tridion 2011 SP1 and Firefox 16.0.2, Internet Explorer 8, Internet Explorer 9 and Chrome 23.0.1271.95.

When I open a component in any of the browsers and delete all text in the Design view of a rich text field (pressing delete and backspace multiple times) I am left with a variety of tags in the Source view. These vary by browser.

  • Firefox : <br />
  • Chrome : <p><br /></p>
  • IE8 : <p></p>
  • IE9 : <p></p>

I have checked the list of hot fixes and there is nothing relevant.

Any ideas?


Solution

  • This sounds like a bug which should be submitted to SDL Customer Support. Does the behavior differ with IE, Chrome and FF?

    Unless support can provide a hot fix, I think your only option is to filter out the lone BR (as Frank suggested) using the filtering XSLT. The default XSLT filter used when creating a new rich text field has this filtering included as shown below (last <template> node).

    <stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
        <output omit-xml-declaration="yes" method="xml" cdata-section-elements="script"></output>
        <template match="/ | node() | @*">
            <copy>
                <apply-templates select="node() | @*"></apply-templates>
            </copy>
        </template>
        <template match="*[      (self::br or self::p or self::div)     and      normalize-space(translate(., &apos; &apos;, &apos;&apos;)) = &apos;&apos;     and      not(@*)     and      not(processing-instruction())     and      not(comment())     and      not(*[not(self::br) or @* or * or node()])     and      not(following::node()[not(         (self::text() or self::br or self::p or self::div)        and         normalize-space(translate(., &apos; &apos;, &apos;&apos;)) = &apos;&apos;        and         not(@*)        and         not(processing-instruction())        and         not(comment())        and         not(*[not(self::br) or @* or * or node()])       )])     ]">
            <!-- ignore all paragraphs and line-breaks at the end that have nothing but (non-breaking) spaces and line breaks -->
        </template>
        <template match="br[parent::div and not(preceding-sibling::node()) and not(following-sibling::node())]">
            <!-- Chrome generates <div><br/></div>. Renders differently in different browsers. Replace it with a non-breaking space -->
            <text> </text>
        </template>
    </stylesheet>