xforms: how to prevent xxforms:default value from over-writing user input
Posted
by
Purni
on Stack Overflow
See other posts from Stack Overflow
or by Purni
Published on 2010-07-16T20:49:34Z
Indexed on
2010/12/28
0:54 UTC
Read the original article
Hit count: 345
I have a dropdown to display status, which can be Enabled(true) or Disabled(false). Here is my xml instance.
<?xml version="1.0" encoding="UTF-8"?>
<page>
<file-name></file-name>
<status></status>
</page>
By default, status should be true. So I have set it in binding as follows.
<xforms:bind nodeset="./status" xxforms:default="true()" />
When user chooses Disabled in the dropdown, the status should get saved as false. Here is the xml that gets saved when I save the form.
<page>
<file-name>StatusDisabled.xml</file-name>
<status>false</false>
</page>
When I open the form in edit mode, this is the xml I get in the XML inspector widget.
<page>
<file-name>StatusDisabled.xml</file-name>
<status>true></status>
</page>
Status gets set to true because of xxforms:default, even though the xml is saved with a false value for status.
How can I fix this?
Here is the xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms">
<head>
<title>XForms Default</title>
<xforms:model>
<xforms:instance id="instance">
<page>
<name xmlns=""/>
<status xmlns=""/>
</page>
</xforms:instance>
<xforms:instance id="status-instance">
<items>
<item label="Enabled" value="true" xmlns=""/>
<item label="Disabled" value="false" xmlns=""/>
</items>
</xforms:instance>
<xforms:bind nodeset="instance('instance')">
<xforms:bind nodeset="./status" xxforms:default="true()" />
</xforms:bind>
</xforms:model>
</head>
<body>
<p>
<xforms:input ref="instance('instance')/name" incremental="true">
<xforms:label>Please enter your name:</xforms:label>
</xforms:input>
</p>
<p>
<xforms:select1 ref="instance('instance')/status" appearance="minimal" incremental="true">
<xforms:label>Please select status:</xforms:label>
<xforms:itemset nodeset="instance('status-instance')/item">
<xforms:label ref="./@label"/>
<xforms:value ref="./@value"/>
</xforms:itemset>
</xforms:select1>
</p>
</body>
</html>
© Stack Overflow or respective owner