Orbeon Forms 中的字段只读行为存在问题。我们通常在绑定定义中编写条件来告诉字段何时应该是只读的,因此当满足条件时,表单(HTML 浏览器)上的字段将不可编辑。
但是,在该字段的 HTML 页面源代码中,我们看到该字段支持属性 disabled="disabled" 但不是 readonly="readonly"。由于属性 disabled="disabled",输入字段中的数据将显示为灰色(IE 浏览器,windows 默认外观),并且看起来模糊/暗淡,因此无法正确查看。此外,我们不能通过 css 属性为禁用字段更改输入数据的颜色,但我们可以对具有属性 readonly="readonly" 的字段执行此操作。
所以问题是,当我们在 Orbeon 代码的绑定定义中说 readonly="true" 时,是否有可能在 HTML 浏览器上将属性设置为 readonly="readonly" 而不是 disabled="disabled"
示例 Orbeon 代码和 HTML 页面源快照如下
<xhtml:html xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:f="http://orbeon.org/oxf/xml/formatting"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<xhtml:head>
<xforms:model xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema" id="main-model">
<xforms:instance id="form-instance">
<form>
<field-1></field-1>
<field-2></field-2>
<field-3></field-3>
</form>
</xforms:instance>
<xforms:instance id="form-attributes">
<attributes>
<summary>false</summary>
</attributes>
</xforms:instance>
<xforms:bind id="summary" nodeset="instance('form-attributes')/summary" />
<xxforms:variable name="summary" select="instance('form-attributes')/summary" />
<xforms:bind nodeset="instance('form-instance')" readonly="$summary='true'" />
<xforms:bind id="field-1" nodeset="instance('form-instance')/field-1" />
<xforms:bind id="field-2" nodeset="instance('form-instance')/field-2" />
<xforms:bind id="field-3" nodeset="instance('form-instance')/field-3" />
</xforms:model>
</xhtml:head>
<xhtml:body>
<table>
<tr>
<td>
<xforms:trigger appearance="minimal" id="readonly-view">
<xforms:label>Readonly View</xforms:label>
<xforms:action ev:event="DOMActivate">
<xforms:setvalue bind="summary" value="'true'" />
</xforms:action>
</xforms:trigger>
</td>
<td>
<xforms:trigger appearance="minimal" id="editable-view">
<xforms:label>Editable View</xforms:label>
<xforms:action ev:event="DOMActivate">
<xforms:setvalue bind="summary" value="'false'" />
</xforms:action>
</xforms:trigger>
</td>
</tr>
<tr>
<td>
Field 1:
</td>
<td>
<xforms:input bind="field-1" id="field-1-id" xxforms:maxlength="10" />
</td>
</tr>
<tr>
<td>
Field 2:
</td>
<td>
<xforms:input bind="field-2" id="field-2-id" xxforms:maxlength="10" />
</td>
</tr>
<tr>
<td>
Field 3:
</td>
<td>
<xforms:input bind="field-3" id="field-3-id" xxforms:maxlength="10" />
</td>
</tr>
</table>
</xhtml:body>
</xhtml:html>
HTML 页面源代码的快照: