XForms: set default selection in dropdown in binding

烂漫一生 提交于 2019-12-11 13:46:16

问题


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>

Main instance binding is as follows:

<xforms:bind nodeset="instance('myinstance')">
    <xforms:bind nodeset="./color" required="true()"/>
</xforms:bind>

回答1:


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>

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>

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'"/>

Also updated to reflect the fact that instance data must contain "Green", not "Color3".



来源:https://stackoverflow.com/questions/3019006/xforms-set-default-selection-in-dropdown-in-binding

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!