Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails. Submit to controller/action on select change

I would like to submit a form to an action on select box change (when an item is selected I need to update another select box and maybe other fields). The following code will submit the form to the controller/action defined on form element.

 <g:select onchange="submit()"/>

How could I submit the form to a custom action ? I think to put a hidden action submit on the page and trigger a click on it when selecting an item in the select box, but hopping there is a more elegant way. The project use jquery, so the prototype library isn't available. Thanks a lot !

like image 648
Bax Avatar asked Feb 06 '26 19:02

Bax


1 Answers

It is an unusal use-case to submit the whole form, just because one combo box is changed. Usually the following is sufficient submitting only the new value of the combo box.

<g:form id="thisForm" action="yourFormAction">
    <g:select                       
        onchange="${remoteFunction(
            action:'yourOnChangeAction',
            update:'thisForm', 
            params:'\'thisInputField=\' + this.value' )}"
        value="${value}" 
        name="productDependencyType" 
        from="${values}" />
</g:form>

However, if your REALLY want to have all other form fields to be submitted as well, I guess it would be the best, to have one dispatching action and your input box sets some hidden field before submitting to the standard form-action. Hidden submit buttons are scary :)

like image 67
Chris Avatar answered Feb 09 '26 10:02

Chris