Home How to limit a multiple selection of a <g:select>
Reply: 1

How to limit a multiple selection of a <g:select>

Javier Escudero
1#
Javier Escudero Published in 2018-01-09 11:35:35Z

I want to limit a multiple selection to 1, because I want this format of list. I want to see all list always and don't want a dropdown list, and If I quit multiple="multiple" apears a dropdown list.

So, this is the code:

gsp:

<div class="field ${hasErrors(bean: cmd, field: 'subtypes', 'error')}">
    <label for="subtypes">
        <g:message code="requestSRO.requestSubtype.label"/>
    </label>
    <g:select name="subtypes" from="${requestSubtypes}" optionKey="code" multiple="multiple" optionValue="description" value="${cmd?.subtypes}" style="width: 100%;height: 100px" disabled="${!requestSubtypes ? true: false}"/>
</div>

I think <g:select> doesn't have a property to set the max limit of selections.

doelleri
2#
doelleri Reply to 2018-01-09 16:55:04Z

Don't use multiple="multiple" to change the way the select is displayed. Instead, set the size attribute to a number greater than 1.

<g:select size="2" name="subtypes" from="${requestSubtypes}" optionKey="code" optionValue="description" value="${cmd?.subtypes}" style="width: 100%;height: 100px" disabled="${!requestSubtypes ? true: false}"/>

If you want to display the entire list of subtypes, you could set size="${requestSubtypes.size()}".

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303858 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO