Reputation: 33
I have a view in Grails that consists of a and a which is populated from a State enum like so
State Code<g:textField name="stateCode" value="${params.stateCode}"/><br/>
State Name<g:select name="stateValue" from="${State.values()}" value="${params.stateValue}"/>
I intend to use this view to allow users to add new States to an enum by entering the two digit postal code in the textField and the full state in the select. To make this easier, I would like to allow the user to type in the value of the enum with the key in the box. For example, if the user typed NY into the textField, they can type New York in the select.
Is there a way in Grails that will allow a 'typeable' select menu? If there is not, I do not mind using jQuery in order to achieve the desired result.
Upvotes: 2
Views: 793
Reputation: 3694
This isn't really a Grails thing per se. There are a few nice javascript libraries you could use to enhance your Grails-generated select
s though:
My personal preference is Select2. You can use it like this:
<g:select name="stateValue" from="${State.values()}" value="${params.stateValue}" class="mySelect" />
<script>
$("select.mySelect").select2();
</script>
Upvotes: 2