lundi 29 février 2016

Can't get value from checkbox Thymeleaf

<input id="isChecked" name="isChecked"
                    type="checkbox"></input><input name="_isChecked"
                    type="hidden" value="on"></input> <label for="isChecked">Checked</label>

I have this checkbox on the top of my *.html. I want to use the value of "isChecked" input in a "form" like seting 1/0 (true/false) to a hidden input:

<form id="someForm" class="form xml-display form-inline"
                th:action="@{/doSomething}" method="post">
.....
    <input type="hidden" name="isChecked"
                       th:value="GET VALUE FROM THE GLOBAL CHECKBOX" />
.....
</form>

So can I do this without any JS? Should I add an object in my java controller to the Model so I can set the value from the "isChecked" checkbox to it and then use the object in th:value="${objectFromJavaController}" for the hidden input ? I tried setting a th:object="${objectFromJavaController}" for the checkbox and then passing it to the hidden input but it didn't work (th:value = ${"objectFromJavaController"}) ?

So can someone help me ? Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire