Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic variable ID

Tags:

thymeleaf

I allow the user to create some customized fields... therefore, I don't know their IDs. While showing such fields in the view, I need to use the value of one variable and use it to get the value of another variable. Currently, th:value="${udfield.id}" will of course only assign the value of "udfield.id". Is this possible?

<div data-th-each="udfield : ${udfields}">
    <label th:text="${udfield.displayText}">User defined field:</label>
    <input th:name="${udfield.id}" type="text" class="form-control" th:value="${udfield.id}"/>
</div>

My Controller sends the values which were extracted from a DB:

for (FieldValue currentFieldVal : userFieldValues){
    attributes.addFlashAttribute(currentFieldVal.getFieldID(), currentFieldVal.getValue());
}
like image 794
DiegoSahagun Avatar asked Mar 15 '23 14:03

DiegoSahagun


1 Answers

What I needed was preprocessing, I found it thanks to this question.

th:value="${__${udfield.id}__}"
like image 79
DiegoSahagun Avatar answered May 08 '23 00:05

DiegoSahagun