0

I have this js function

import numberToWordsRu from 'number-to-words-ru';
function convert(number)
{
    return numberToWordsRu.convert(number);
}

And I want to call it in th:text for passed argument. Something like this:

<p th:text="'This ' + ${param} + ' is ' + convert(${param})">
</p>

Is it possible and how it how to do it right?

Dimitry
  • 99
  • 6
  • This might work th:onclick="'myFunction() And you can refer https://stackoverflow.com/questions/26526037/javascript-function-call-with-thymeleaf – SnehalM Jun 22 '21 at 13:49
  • This might work th:onclick="'myFunction() And you can refer https://stackoverflow.com/questions/26526037/javascript-function-call-with-thymeleaf – SnehalM Jun 22 '21 at 13:51
  • It is important to understand that Thymeleaf runs on the server. It generates HTML from the templates and then sends the HTML to the browser that displays it. At that point, JavaScript can start to work, but Thymeleaf will no longer do anything. – Wim Deblauwe Jun 22 '21 at 13:57
  • This is what I want, I want to change the input value using function at the start. – Dimitry Jun 23 '21 at 07:15

1 Answers1

0

The th:text attribute evaluates its value expression and sets the result of this evaluation as the body of the tag it is in. It is not possible to use javascript function with th:text

Nemanja
  • 3,295
  • 11
  • 15