Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 1222 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to set the id attribute of HTML element dynamically with Thymeleaf

#1
Lets say I have an object : ${object}

and I have the following form:

<form id="{{'myForm' + object.id}" class="some class"
th:action="@{/doSomething}" method="post">
....
</form>

My goal is to set the id = "myForm1" if we assume that the object.id is '1'.

PS: The way I wrote it's working on Angular JS.

Reply

#2
You have to use th:id attribute:

<form th:id="'myForm' + ${object.id}" class="some class" th:action="@{/doSomething}" method="post">
// *** Other code here ***
</form>
Reply

#3
Here is how you can use dynamic id with label:

<th:block th:with="randomId=${#strings.randomAlphanumeric(10)}">
<input type="checkbox" th:id="${randomId}">
<label th:for="${randomId}"></label>
</th:block>
Reply

#4
There is still another (nice) way to accomplish this.

Assuming you are iterating a list of items as shown below, you can use the following `th:id` to set the id using the index of the item being iterated.

<th:block th:each="item : ${list}">
<div class="tab-pane active" th:id="@{|#div-id-${itemStat.count}|}"></div>
</th:block>

This example sets an id on a `<div>`. Note that `itemStat` is a fixed name given the iterator name as `item`.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through