I have a form that takes several inputs from the user to create an object and one of these inputs are a set of checkboxes.
The checkboxes are generated from a Model
with an ArrayList
with Grape
objects called "GrapeList" but I can't manage to figure out how to add them to the object that is created when submitting the form.
My form looks like this:
<form class="col-12" action="#" th:action="@{/admin}" th:object="${Wine}" method="post">
<div class="row">
<div class="col-1">
<label for="nameInput">Name: </label>
</div>
<div class="col-11">
<input class="w-100" id="nameInput" type="text" th:field="*{name}">
</div>
</div>
<div class="col-1">
<label for="descriptionInput">Description: </label>
</div>
<div class="col-11">
<textarea class="w-100" id="descriptionInput" type="text" th:field="*{description}"></textarea>
</div>
</div>
====================PROBLEM=======================
<div class="row" th:each="grape: ${GrapeList}">
<div class="col">
<label th:for="'grape' + ${grape.name}" th:text="${grape.name}"></label>
</div>
<div class="col">
<input type="checkbox" th:id="'grape' + ${grape.name}" th:value="${grape.id}" th:field="*{grapes.add()}">
</div>
</div>
====================PROBLEM=======================
<button class="btn btn-outline-success" type="submit" value="Submit">Save</button>
</form>
The form is creating a Wine
Object that has an ArrayList
with Grape
Objects called "grapes". The other input fields works fine but I dont know how to bind the arraylist to add a grape object for every checked box..
The th:field="*{grapes.add()}"
is just there to describe what I'm trying to do..
Any help is appreciated!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…