Search code examples
grailsgroovygsp

GSP form parameter appended to params - need overwrite


I have the following form:

<g:form controller="${controllerName}" action="${actionName}" params="${params}">
    <g:select name="publisher_status" from="${['Active']}" value="${publisher_status}" noSelection="${[null:'No Filter']}" />
    <button type="submit" class="btn btn-default btn-primary btn-sm ">Apply</button>     
</g:form>

Each time I submit this form, publisher_status value is appended to the previous one, resulting in a list like publisher_status=[null,'Active'] etc. What I really need is to overwrite the previous value, so I always have just a string. I tried the following above and below the above form, but it is not working:

  <g:set var="params" value="${params.remove('publisher_status')?params:params}"/>

Any suggestions as to how to get around this issue ?


Solution

  • You can't set params like that, but you can filter the map that you pass to g:form:

    <g:form controller="${controllerName}" action="${actionName}"
            params="${params.findAll {k, v -> k != 'publisher_status'}}">