I'm trying to implement a select using Ajax, following this tutorial: https://halleysweblog.wordpress.com/2014/02/19/ajax-driven-selects-in-grails/
But nothing works. Follows the code :
selectChain.gsp
<!DOCTYPE html>
<html>
<head>
<meta name="layout" content="main"/>
<title>Cadastro de Cidade</title>
<g:javascript library="jquery" />
</head>
<body>
<div>
<div>
<g:select name="country.id" from="${teste}" optionKey="id"
optionValue="name" noSelection="['':'Select Country']"
onchange="${remoteFunction (controller: 'country',
action: 'findCityForCountry',
params: '"country=" + this.value',
update: 'citySelection'
)}" />
</div>
<div id="citySelection">
<select>
<option>Select City</option>
</select>
</div>
</div>
</body>
</html>
Controller:
package projetoaep
class CountryController {
def index() {
render(view: "/country/selectChain")
}
/*
* Finding the cities for a specific country
*/
def findCityForCountry() {
def country=Country.get(params.country)
render(template: 'citySelection', model: [cities: country.cities])
}
/*
* For the view
*/
def selectChain() {
[teste : Country.list()]
}
}
citySelection.gsp
<!-- This template renders a drop down after a country is selected -->
<g:select name="city.id" from="${cities}" optionValue="name"
optionKey="id"/>