Default text inside <textarea> only visible without th:field attribute

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Default text inside <textarea> only visible without th:field attribute

apprentice
Default text  is not displayed when the "th:field" attribute is set. Text visible with this attribute removed.

<textarea th:field="*{foobar}" >123</textarea>

The dom has the id and name field present. It also has the correct field name e.g.

dom output

<textarea id="foobar" name="foobar"></textarea> <-- no text

Reply | Threaded
Open this post in threaded view
|

Re: Default text inside <textarea> only visible without th:field attribute

Metroids
The reason th:field attribute exists is to replace the value of a form field with the contents of the specified variable (foobar in this case).  If you want to default text to the textarea you should either:

1) Set the contents of foobar in the controller itself, before the page is rendered. e.g. object.setFoobar("
123");

2) Use some alternative... such as the html 5 placeholder element.