Monday, October 25, 2010

Undefined text in Page Editor when clearing field


Greetings!

You may be experiencing an issue with Page Editor in Sitecore 6.1/6.2 releases when clearing a field results in “Undefined” text being written back to your item.

To work this around, follow these 3 easy steps.

1. Locate the following file: <web root>\sitecore\shell\Applications\WebEdit\WebEditElement.js
Create a backup copy of it.

2. Find the following function: Sitecore.WebEdit.Element.prototype.load = function() and replace it with this:

Sitecore.WebEdit.Element.prototype.load = function() {
  if (this.element.getAttribute("scWatermark") == "true") {
    this.element.removeAttribute("scWatermark");
    this.watermarkHTML = this.element.innerHTML;
  }else
  {
  this.watermarkHTML = "[No text in field]";
  }
this.buttons.select(".scWebEditFrameButtonIcon").each(function(icon) {
    icon.observe("dragstart", function(e) { e.stop(); });
  });
  this.element.observe("click", this.onClick.bind(this));
  this.element.observe("blur", this.onBlur.bind(this));
}

3. Then locate this function: Sitecore.WebEdit.Element.prototype.isWatermark = function() {
and replace it with this:

Sitecore.WebEdit.Element.prototype.isWatermark = function() {
  fl=false;
  if((this.watermarkHTML == this.element.innerHTML)||(this.element.innerHTML=="[No text in field]"))
               {
               fl=true;
               }
  return fl;
}

Quick disclaimer: this proved working on my local 6.2.0 (rev. 100831) installation, however, this is not a fully tested solution, so there may be conflicts depending on exact version of your Sitecore instance and level of customization.

Thanks goes to Sitecore Customer Service for quick solution!