Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I correctly set the required HTML attribute to an input tag into a TymeLeaf page?

I am pretty new in Spring MVC and absolutly new in ThymeLeaf.

So I am working on a web application that use TymeLeaf as view technology and I have to use this Jquery Validation Plugin: http://jqueryvalidation.org/

So I have used it in the past into JSP pages.

As shown in the documentation: http://jqueryvalidation.org/documentation/

I have to add the required attribute to my input tag that have to be fill by the user, something like this:

<input id="cemail" type="email" name="email" required>

I tryied to do this thing into my TymeLeaf HTML page, in this way:

<input id="nome" name="nome" type="text" th:value="*{nome}" required></input>

But the problem is now I obtain this error message in the stacktrace console and the page is not renderd:

15:36:47,180 ERROR [org.thymeleaf.templateparser.ErrorHandler] (http-localhost/127.0.0.1:8080-3) [THYMELEAF][http-localhost/127.0.0.1:8080-3] Fatal error during parsing: org.xml.sax.SAXParseException; lineNumber: 88; columnNumber: 78; Attribute name "required" associated with an element type "input" must be followed by the ' = ' character.
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:196)
    at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:175)  

Why? What is wrong? How can I correctly set the required HTML attribute to an input tag declated into a ThymeLeaf page?

like image 636
AndreaNobili Avatar asked Oct 05 '15 13:10

AndreaNobili


2 Answers

Use it:

<input id="cemail" type="email" name="email" required="true" />

The Thymeleaf Standard Dialect can process templates in any mode, but is especially suited for web-oriented template modes (XHTML and HTML5 ones). Besides HTML5, it specifically supports and validates the following XHTML specifications: XHTML 1.0 Transitional, XHTML 1.0 Strict, XHTML 1.0 Frameset, and XHTML 1.1.

See More On : http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#what-is-thymeleaf

like image 181
Bhuwan Prasad Upadhyay Avatar answered Nov 01 '22 22:11

Bhuwan Prasad Upadhyay


The correct way to declare the required attribute in HTML5 with thymeleaf is th:required="required".

Try:

<input id="nome" name="nome" type="text" th:value="*{nome}" th:required="required"></input>
like image 45
ronielhcuervo Avatar answered Nov 01 '22 21:11

ronielhcuervo