Search code examples
grailsgsp

Grails link with params and confirmation


Hi I want to make a delete link to some action on controller. My link looks like this:

<td>
     <g:link action="delete" params="[branchID:branch.id]" onclick="'Are you sure?'">
         <i class="glyphicon glyphicon-trash"></i>
     </g:link>
</td>

I want to make user confirm his action onclick="'Are you sure?'". I checked documentation, but I did not find anything useful. It does not have to be <g:link, I would be happy for any solution. I have <g:each and I want to perform classic update and delete action on every object in the list.


Solution

  • try this. For your wish i have written inside g:each

       <g:each in="${instance}" var="it">     
          <td><g:link action="delete" params="[branchID:${it.id}]" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');"><i class="glyphicon glyphicon-trash"></i></g:link></td>
       </g:each>