I have following select in a template that I render, passing i in the model. ${i} get’s replaced with the value of i, as expected in most places. But ${i} is not getting replaced in the onchange event.
So,
<g:select class='setTagtypeValue-class'
name='tagtype-${i}-header'
from="${org.maflt.ibidem.Tagtype.list(sort:'tagtype').groupBy{it.tagtype}.keySet()}"
value="${setTagtypeValue?.tagtype?.tagtype}"
noSelection="${['null':'Select One...']}"
onchange="${remoteFunction(action:'options', update:'tagtype-options-${i}',
params:'\'tagtype=\' + this.value +\'&i=${i}\'' )}" />
gets rendered as:
<select name="tagtype-0-header" onchange="jQuery.ajax({type:'POST',data:'tagtype=' + this.value +'&i=${i}', url:'/ibidem/metadataSet/options',success:function(data,textStatus){jQuery('#tagtype-options-${i}').html(data);},error:function(XMLHttpRequest,textStatus,errorThrown){}});" class="setTagtypeValue-class" id="tagtype-0-header">
<option value="null">Select One...</option>
<option value="abstract">abstract</option>
. . .
</select>
Notice that, for example, name has been set to “tagtype-0-header”, but in the onchange I’m getting
data:'tagtype=' + this.value +'&i=${i}'
Also note that when this template is used during Create, where the substition happens client side, everything works as expected. So the only problem is that during Edit, working server-side, ${i} isn’t getting replaced within the onchange event.
Any ideas?
Since you’re already inside of a
${}, the inner${}is going to be ignored. Try this out: