Reputation: 1
How to show first element of dropdown menu instead of "Please select"? I am loading elements in 2 dropdown menus like this:
<xf:instance id="makes">
<root>
<item name="Tesla" value="Tesla"/>
<item name="Toyota" value="Toyota"/>
<item name="Suzuki" value="Suzuki"/>
<item name="Jeep" value="Jeep"/>
<item name="Alfa" value="Alfa"/>
</root>
</xf:instance>
<xf:instance id="models">
<root>
<item makeValue="Tesla" modelValue="Tesla S" modelName="Tesla S"/>
<item makeValue="Tesla" modelValue="Tesla X" modelName="Tesla X"/>
<item makeValue="Tesla" modelValue="Tesla Roadster" modelName="Tesla Roadster"/>
<item makeValue="Alfa" modelValue="Brera" modelName="Brera" />
<item makeValue="Alfa" modelValue="Giulietta" modelName="Giulietta"/>
<item makeValue="Alfa" modelValue="Spider" modelName="Spider"/>
<item makeValue="Alfa" modelValue="MiTo" modelName="MiTo"/>
<item makeValue="Alfa" modelValue="GT" modelName="GT"/>
<item makeValue="Suzuki" modelValue="Swift" modelName="Swift"/>
<item makeValue="Suzuki" modelValue="Samurai" modelName="Samurai"/>
<item makeValue="Suzuki" modelValue="Vitara" modelName="Vitara" />
<item makeValue="Toyota" modelValue="Corolla Verso" modelName="Corolla Verso"/>
<item makeValue="Toyota" modelValue="Aygo" modelName="Aygo" />
<item makeValue="Toyota" modelValue="Yaris" modelName="Yaris" />
<item makeValue="Toyota" modelValue="Avensis" modelName="Avensis"/>
<item makeValue="Toyota" modelValue="Rav4" modelName="Rav4"/>
<item makeValue="Jeep" modelValue="Grand Cherokee" modelName="Grand Cherokee"/>
<item makeValue="Jeep" modelValue="Commander" modelName="Commander"/>
<item makeValue="Jeep" modelValue="Compass" modelName="Compass"/>
<item makeValue="Jeep" modelValue="Liberty" modelName="Liberty"/>
<item makeValue="Jeep" modelValue="Patriot" modelName="Patriot"/>
<item makeValue="Jeep" modelValue="Renegade" modelName="Renegade"/>
</root>
</xf:instance>
And than bind them:
<xh:tr>
<xh:td>
<xf:select1 id="vehicle-make-control" bind="vehicle-make-bind" appearance="dropdown">
<xf:label ref="$form-resources/vehicle-make/label"/>
<xf:hint ref="$form-resources/vehicle-make/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
<xf:itemset ref="instance('makes')/item">
<xf:label ref="@name"/>
<xf:value ref="@value"/>
</xf:itemset>
</xf:select1>
</xh:td>
</xh:tr>
Same thing is for models, just control name is vehicle-model.
When i select vehicle make i got appropriate models for specified veh. make, but first element is please select of blank. I need to show Tesla S as first when Tesla is selected etc.
To have it like this:
OPEN PICTURE.
I set in initial value XPath expression $(.)[1]
but it is not working.
Upvotes: 0
Views: 123
Reputation: 31743
I imagine this is for a form you created with Form Builder, and to which you added the <xf:instance id="makes">
and <xf:instance id="models">
by editing the source of the form.
If so, if you want the dropdowns to have the first item as their initial value, instead of "Please select", then you'll want to set the initial value of the field to the value of the first item. You can do so in the Control Settings dialog, in the Formulas tab. You can do so with an expression like:
instance('makes')/item[1]/@value
Upvotes: 2