Question

I need to set custom attribute (data-validation-matches-message) value from messages resources.

<input data-validation-matches-message="Text from messages resources" />

I can receive and print messages resources value as:

<p th:text="#{user.notfound}"></p>

But how I can set this value for a custom attribute (data-validation-matches-message)?

UPD (I use this)

<input th:attr="data-validation-matches-message=#{user.notfound}"/>
Was it helpful?

Solution 2

Try this:

<input th:attr="data-validation-matches-message='\'' + #{user.notfound}" + '\''"/>

OTHER TIPS

Since Thymeleaf 2.1 you can do this:

<a data-th-attr="data-groupid=${somevalue}, data-groupname=${someothervalue}">...</a>

source

Using 3.0.9.RELEASE:

<td th:text="${item.description}" th:attr="width=${isSplit} ? '44%' : '59%'" />

This will add width="44%" or width="59%according to a boolean set in the variables. width might as well have been any other custom attribute.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top