michmech / xonomy

A schema-driven XML editor for the web.
MIT License
91 stars 32 forks source link

Can't edit content of XML with empty tag #19

Open jasoncslaughter opened 7 years ago

jasoncslaughter commented 7 years ago

I have an xml document that includes empty tags:

<dataStatistics>
  <statistic></statistic>
<dataStatistics>

I have specified in the settings that the content of <statistics> should be settable (at least if I understand correctly).

elements: {
   "statistic": {
      asker: Xonomy.askString,
      menu: [
         {
             caption: "Delete this <statistic>",
             action: Xonomy.deleteElement
         }
       ]
   }
}

In the editor, the <statistic> tag appears as <statistic/>, and there appears no way to add text content inside of it.

Is this a bug, or am I doing something wrong?

MarkPerryBV commented 6 years ago

Here is a workaround I just came up with until this is sorted correctly.

var stdMenu = [
            {
                caption: "Make Null",
                action: function(htmlID, actionParameter) {
                    Xonomy.editRaw(htmlID, actionParameter);
                },
                actionParameter: {
                    fromJs: function(jsElement) {
                        return "<" + jsElement.name + " />";
                    },
                    toXml: function(txt, origElement) {
                        return txt;
                    }
                }
            },
            {
                caption: "Make ?",
                action: function(htmlID, actionParameter) {
                    Xonomy.editRaw(htmlID, actionParameter);
                },
                actionParameter: {
                    fromJs: function(jsElement) {
                        return "<" + jsElement.name + ">?</" + jsElement.name + ">";
                    },
                    toXml: function(txt, origElement) {
                        return txt;
                    }
                }
            }
        ];
var docSpec = {
  elements: {
     "MessageID": { oneliner: true, menu: stdMenu }
  }
}

Now when you "click" on the element name it will pop open this standard menu and use the inbuilt "editRaw" function to set the contents of the element.

viceice commented 6 years ago

@rexrhino You should set hasText:true for the statistics element.