XForms:在绑定的下拉列表中设置默认选择 [英] XForms: set default selection in dropdown in binding
问题描述
我有一个名为myinstance"的主实例,它具有元素颜色.颜色可以是红色"、蓝色"、绿色"或黄色".颜色填充在另一个名为colorsinstance"的实例的下拉列表中.当我的表单加载时,我希望在节点集绑定中将下拉列表中的默认值设置为绿色".
I have a main instance named 'myinstance' which has the element color. Color can be 'Red', 'Blue', 'Green' or ''Yellow'. The colors are populated in a drop-down from another instance called 'colorsinstance'. When my form loads, I want the default in the dropdown to be set to 'Green' in the nodeset binding.
<instance id="colorsinstance">
<items>
<item label="Color1" value="Red"/>
<item label="Color2" value="Blue"/>
<item label="Color3" value="Green"/>
<item label="Color4" value="Yellow"/>
</items>
</instance>
主要实例绑定如下:
<xforms:bind nodeset="instance('myinstance')">
<xforms:bind nodeset="./color" required="true()"/>
</xforms:bind>
推荐答案
下拉列表的默认值将反映存储在实例中的值.您可以将默认值直接放在您的实例中,例如:
The default value of the dropdown will reflect the value stored in the instance. You can either put the default directly in your instance, e.g.:
<color>Green</color>
或者您可以使用 setvalue 设置值,例如这在您的模型中:
Or you can set the value using setvalue, e.g. this in your model:
<xforms:setvalue ev:event="xforms-model-construct-done"
ref="color">Green</xforms:setvalue>
根据您的评论进行更新:如果您想使用 Orbeon Forms xxforms:default 扩展名,请尝试:
Updated following your comment: if you want to use the Orbeon Forms xxforms:default extension, then try:
<xforms:bind nodeset="./color" required="true()" xxforms:default="'Green'"/>
还更新以反映实例数据必须包含Green"而不是Color3"这一事实.
Also updated to reflect the fact that instance data must contain "Green", not "Color3".
这篇关于XForms:在绑定的下拉列表中设置默认选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!