Is there a way to wrap marked text in element using xforms? For example:
Put tag around this word
-->
Put tag around this <tag>
word</tag>
I'm new to xforms, currently using Xsltxforms on exist-db server and I'm trying to figure out if I'm missing something or there's no way to make such a thing in textarea box for example. Thank you in advance!
There is no mechanism in XForms Recommendation for such a processing.
But this has been added as an extension in XSLTForms: an extra action named "xf:wrap" allows to indicate with control is to be considered and what is to be added before and after the selection.
<?xml-stylesheet href="xsl/xsltforms.xsl" type="text/xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events">
<head>
<title>Wrap Selection</title>
<xf:model>
<xf:instance>
<data xmlns="">Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo.</data>
</xf:instance>
</xf:model>
</head>
<body>
<xf:trigger>
<xf:label><a></xf:label>
<xf:wrap ev:event="DOMActivate" control="t" pre="<a>" post="</a>"/>
</xf:trigger>
<xf:trigger>
<xf:label><b></xf:label>
<xf:wrap ev:event="DOMActivate" control="t" pre="<b>" post="</b>"/>
</xf:trigger>
<xf:trigger>
<xf:label><c></xf:label>
<xf:wrap ev:event="DOMActivate" control="t" pre="<c>" post="</c>"/>
</xf:trigger>
<br/>
<xf:textarea id="t" ref="." incremental="true"/>
<br/>
<xf:output value=".">
<xf:label>Value: </xf:label>
</xf:output>
</body>
</html>
There is yet another possibility with the xf:setselection action:
<?xml-stylesheet href="xsl/xsltforms.xsl" type="text/xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events">
<head>
<title>Set Selection</title>
<xf:model>
<xf:instance>
<data xmlns="">Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium...</data>
</xf:instance>
</xf:model>
</head>
<body>
<xf:trigger>
<xf:label><span></xf:label>
<xf:setselection ev:event="DOMActivate" control="t" value="concat('<span start="', control-property('t', 'selectionStart'), '" end="', control-property('t', 'selectionEnd'), '">', selection('t'), '</span>')"/>
</xf:trigger>
<br/>
<xf:textarea id="t" ref="." incremental="true"/>
<br/>
<xf:output value=".">
<xf:label>Value: </xf:label>
</xf:output>
</body>
</html>
Live demo: http://www.agencexml.com/direct/wrap/setselection.xml
What do you think?