alwinc
alwinc

Reputation: 1327

Spring forms:input HTML5 required attribute

I am using Spring forms and would like to use the HTML5 'required' attribute which Spring forms does not seem to support.

<form:input path="someinput" cssClass="required"/>

I cannot seem to do

<form:input path="someinput" cssClass="required" required="required"/>

as this is currently not supported by the Spring TLD.

It seems like I NEED to ditch spring forms if I want to use the full HTML5 spec

<input name="someinput" id="someinput" class="required" required="required"></input>

Does anyone know how I can implement the required field with spring forms 3.1.3.RELEASE? Thanks!

Upvotes: 1

Views: 5735

Answers (2)

Igor Vuković
Igor Vuković

Reputation: 763

just add some jquery at the end of the page

    <html>
    <body>
            <form:input path="someinput" id="someinput"/>
    </body>
    <script>
            $("#someinput").attr('required', ''); 
    </script>
    </html>

Upvotes: 3

LazyChild
LazyChild

Reputation: 84

  1. If you just submit the form with default commandName, your approach is ok.
  2. Better way to solve it: Write the form with spring-form and forget the required thing. Then find out what the real html spring-form generated for you. Write the html your own and add the required field.

Upvotes: 0

Related Questions