Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

In Thymeleaf I have this situation:

<select class="form-select input-widget" id="treat" tabindex="31" th:field="*{treat}"> <option value="">Please select...</option> <option th:each="v : ${@baba.getTreat()}" th:value="${v.key}" th:text="${v.value}"></option> </select>

and I have

String treat;

and i.e.

<option value="mynum">One</option

Now th:field maps the key (value attribute from option tag, in the example above "mynum") to the "treat" variable. But I want that the variable "treat" contains "One". How can I achieve this?

Thank you in advance!

You must be logged in to vote

Replies: 1 comment · 1 reply

Comment options

what about this?

<select class="form-select input-widget" id="treat" tabindex="31" th:field="*{treat}">
    <option value="">Please select...</option>
    <option th:each="v : ${@baba.getTreat()}" th:data-key="${v.key}" th:text="${v.value}" th:value="${v.value}"></option>
</select>
You must be logged in to vote
1 reply
@pellerito
Comment options

Hi @landsman,
thank you for the response. I tried it, but unfortunately it doesnt work. In this case the treat variable stores neither the key nor the value. Honestly i doesnt understand the th:data-key attribute, it isnt a default thymeleaf attribute. Do you have another idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.