Reputation: 47
I have followed the tutorial on http://grails.org/AJAX-Driven+SELECTs+in+GSP and successfully created a drop down list that is populated based on the selection of a previous list. The problem I am running into is that I need to allow the auto populated list to have a null value as this field is not required. I am sure this is simple enough but I just can't seem to find any way to do this.
My code is the same as posted on the website above so I will avoid duplicating it here. Thanks!
Upvotes: 0
Views: 169
Reputation: 17916
or use the "noSelection" attribute of
<g:select ... noSelection="['':'-none-']"/>
then the "rebuild-script" will rebuild this empty no-selection automatically
Upvotes: 0
Reputation: 187379
Rather than writing all the code yourself, you could either use this jQuery plugin or this Grails plugin to do some of the work for you. I haven't used the Grails plugin myself, but I have used the jQuery plugin and found it very helpful.
Upvotes: 0
Reputation: 24776
Right before the // Rebuild the select
add in a blank option. For example:
var opt = document.createElement('option');
opt.text = ""
opt.value = ""
try {
rselect.add(opt, null) // standards compliant; doesn't work in IE
} catch(ex) {
rselect.add(opt) // IE only
}
// Rebuild the select
Upvotes: 1