1

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!

alwinc
  • 1,317
  • 3
  • 14
  • 21

2 Answers2

3

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>
Igor Vuković
  • 742
  • 12
  • 25
0
  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.
LazyChild
  • 84
  • 4