Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting list of selected checkboxes in table

This is what I have in table:

<td><g:checkBox name="book_${bookInstance.id}"/> </td>

And this is how I try to get selected instances:

params.each{
            if(it.key.startsWith("book_"))
                books << (it.key - "book_") as Integer
        }

I'm getting an empty list. How to fix this? I'm open to suggestions if u have a better solution.

like image 937
drago Avatar asked Jan 18 '23 02:01

drago


1 Answers

Try creating the list of checkboxes with all the same input name, but different values.

<g:each in="${books}" var="bookInstance">
    <g:checkBox name="books" value="${bookInstance.id}"/>
</g:each>

Then in your controller you can get the list of selected book IDs via:

params.list('books')
like image 62
doelleri Avatar answered Jan 30 '23 23:01

doelleri