Alex Nikolsky
Alex Nikolsky

Reputation: 2169

How to display validation error inside of an input field?

In my rails app I'm using simple_form. I need to get the error messages in the input field instead of it being displayed on the side, like the image shown below.

enter image description here

How can I do this?

Upvotes: 1

Views: 144

Answers (1)

ivywit
ivywit

Reputation: 483

You could use CSS to move the error field into the area of the input field.

example.html.erb

<div class="row">
  <%= f.text_field :email, class: "email" %>
  <span class="error">
</div>

example.css

.row .error {
   margin: -20px;
}

example: http://codepen.io/phelpsiv/pen/ZOaomq

Upvotes: 1

Related Questions