I have an Orbeon Form containing a DropDown Menu. This one is populated (all country names) by an action at Form Load from an SQL Datasource. Both Label and Value are populated.
How to have a default value selected instead of the [Select...] ? In this case, I know the Value of the default item to be selected.
The simplest way to do this is to include the value in the fr-form-instance in the model.
For example:
<xf:instance id="fr-form-instance">
<form>
<section-1>
<country>CHE</country>
</section-1>
</form>
</xf:instance>
There are other ways, as discussed at XForms: set default selection in dropdown in binding
Regards
jez
Related
I have 2 dropdowns (country_1 and country_2) populate with countries. Both are required. If I choose value some in the country_1 dropdown, the country_2 dropdown should be cleared (value and label).
Example:
In the country_1 dropdown I choose something.
In the country_2 dropdown I choose something.
In the country_1 dropdown I change value. country_2 should be cleard.
When I validate form I get error on country_2 dropdown (so it seems that the value has been cleared).
I would like to in step 3 the country_2 will have empty label.
I have added value change action to country_1 dropdown, that should clear country_2 dropdown value and label.
Example form:
https://demo.orbeon.com/demo/fr/orbeon/builder/edit/bc71b6532f4faee1ec711105a2db00bb65995d80
Source code: https://gist.github.com/mmakos-profidata/9728f086da3abc7bd96af27c8d5a70b8
Error screen:
Moving your code to be inside the <xf:model> does the trick. I've updated your form on demo.orbeon.com, but in case it disappears, this is the snippet that I put directly inside the <xf:model>:
<xf:action event="xforms-value-changed" observer="c_country_1-control">
<xf:action if="//c_country_1 != 'af'">
<xf:setvalue ref="//c_country_2"/>
<xf:setvalue ref="//c_country_2/#label"/>
</xf:action>
</xf:action>
I had a requirement of making drop down read only in Grails gsp page. I had two gsp pages create and show. In create user select an element in drop down and submits the selection. In show.gsp, I would like to fetch and show the same element( element selected in create page ) and drop down must be readonly.
Example :
Create.gsp : drop-down 1 2 3
User selected 3
Show.gsp : drop-down must be readonly with value 3
You can disable the input, this does mean the value won't be submitted but if this is a read only view it shouldn't matter, if it does you could add a hidden field for the real value
<g:select name="mySelect" from="${[1,2,3]}" value="3" disabled="disabled" />
I have a viewmodel with a state dropdownlist.
The form is being populated from a database and I everything works except I dont know how to apply the current value for state as the default value for the select helper tag?
This is the CSHTML for the select:
<select asp-for="State" asp-items="#Model.StatesList" > </select>
This provides the all the states when you do a dropdown however is there a way to set the value to the current value for Model eg #Model.state so if you dont select any new dropdown value it takes the original value for the record?
I have a JSP page where am printing the arraylist content via an iterator
<s:iterator var="BeanList" value="BeanList">
<option value='<s:property value="#BeanList.simpleID"/>'>
<s:property value="#BeanList.simpleText" />
</option>
</s:iterator>
Every time the user selects an option, the form submits to the action handling. I want to be able to take the value of the clicked option, and when the page is reloaded after the submit, the same value persists in the select drop down.
Any help will be greatly apprecaited,
You are using HTML Select Tag, with values populated from Struts2 Property Tag.
No JSTL is involved.
But believe me, you can avoid this using the Struts2 Select Tag directly.
Official documentation: http://struts.apache.org/release/2.3.x/docs/select.html
In Action
#Getter #Setter List<String> allCities;
#Getter #Setter String selectedCity;
In JSP:
<s:select list="allCities"
name="selectedCity" />
Faster and cleaner than iterating manually :)
Eventually you can add an optional header value:
<s:select list="allCities"
name="selectedCity"
headerKey="-1"
headerValue="Select a City" />
For that you need to declare a variable with select box name in Action class, and put setter and getter for that. And then, when you are submitting the form, the name matches and it automatically populate in Action class.
When retrieving the data set value to same variable.Then it will populate automatically by using name.
This will happen by using params interceptor internally.
I have a select tag in my GSP file as
<g:select name="clientId" id="clientId" size = "4" from="${com.springcommunity.fleet.partymodel.roles.ClientRole.list()}" class = "filter_combo" optionKey="id" />
i want client with id 2 is selected initially (in simple html it is achived by using selected="selected")
how can i do it?
You need to specify the value attribute in this tag. http://grails.org/doc/2.0.x/ref/Tags/select.html
So in your example,
<g:select ... value="${com.springcommunity.fleet.partymodel.roles.ClientRole.get(2)}" />
One thing to be aware of here is that the value that you're selecting must be an object equal to the item in the list, and not just an id - this is where a lot of people get tripped up. So you can't just say value='2', you need to specify the object in the list that you have in your from attribute.
From the docs -
value (optional) - The current selected value that evaluates equals()
to true for one of the elements in the from list.