donguy76
donguy76

Reputation: 640

<g:checkBox> click calling a controller function

When the user clicks on the checkbox, I want to call a controller function and pass the current status of checkbox, whether it's checked or not.

I know how to do this using jQuery but I want to do this from the checkBox itself.

<g:checkBox id="customer_checkbox" name="customer_checkbox" value="${checked}" />

Controller function to be called:

class updateController {
   def updateIndex () {
      // do something
   }
}

Upvotes: 1

Views: 2025

Answers (2)

Koloritnij
Koloritnij

Reputation: 1217

U need to use remoteFunction from grails taglib. This tag generate for u ajax function:

<select from="[1,2,3,4,5]" onchange="${remoteFunction(action: 'updateIndex', controller:'update',options: '[asynchronous: true]'}" />

For more information go to docs

Upvotes: 3

vivwilfer
vivwilfer

Reputation: 174

The checkbox would be a part of the form. Use javascript to invoke the action.

<g:form name="formName" controller="updateController" action="updateIndex">
    <!-- Other form elements -->
    <g:checkBox id="customer_checkbox" name="customer_checkbox" value="${checked}" onChange="document.getElementById('formName').submit();"/>
</g:form>

Upvotes: 1

Related Questions