I can't see this question anywhere else, it's hopefully a quick and easy one.
How can I use HTML5 validators, such as 'required', in my forms (ruby on rails)?
Eg, How would this basic form look if I used HTML5 validation in it?
<%=form_for @testimonial do |t|%>
<dl>
<dt><label for="testimonial_rating">Rating</label></dt>
<dd><%=t.select :rating, Testimonial.ratings%></dd>
<dt><label for="testimonial_content">Comments</label></dt>
<dd><%=t.text_area :content, :rows => 3%></dd>
<dd><button class="button success">Submit Review</button></dd>
</dl>
<%end%>
It goes without saying that server side validation is still required.
This could be easily done by adding
:required => true
parameter into your input fields:For example
Pushing the boundary abit further, you could add in pattern matcher for your input, such as email:
New Syntax
<%= f.text_field :email, class: "form-control", required: true %>
Addition to @prashantsahni answer. You can also use type = 'email' instead of regex pattern, then your erb-template will look like this:
More info about form validations using html5
Use this if nothing works
Ah, it was easy
:required => true
eg:
<%=t.text_area :content, :rows => 3, :required => true%>
This is a little example with the common attributes and for required you only add required:true, but dont forget apply this validations in your backend.