michmech / xonomy

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

function call fails for jsElement.value from within element specification for displayValue #15

Closed foo4thought closed 7 years ago

foo4thought commented 7 years ago

the following works within attributes specifications but (similar) fails when attempting to use for element specification:

displayValue: function(jsAttribute) {if($.trim(jsAttribute.value)==""){return "MISSING VALUE"}else {return ""+jsAttribute.value} },

i.e., this fails: displayValue: function(jsElement) {if($.trim(jsElement.value)==""){return "MISSING VALUE"}else {return ""+jsElement.value} }, with "undefined" output

michmech commented 7 years ago

This is a feature, not a bug. You should be calling jsElement.getText() instead of jsElement.value.

The value property is defined only for attributes and text nodes. Elements don't have values. Instead, they have children which can be any combination of elements and text nodes. You can access the children of an element through jsElement.children which returns an array of elements and text nodes. Or, if you are only interested in the (recursive) concatenation of all text nodes inside the element, call jsElement.getText().