Display the error message after the label title instead below the input fields

29 views
Skip to first unread message

Sabbu

unread,
Oct 9, 2015, 10:49:54 AM10/9/15
to SimpleForm
When there is validation error on form the validation error message are display after the input text box like this:

<div class="input string required test_last_name field_with_errors">
<label class="string required" for="test_last_name"><abbr title="required">*</abbr> Last name</label>
<input class="string required" id="test_last_name" name="test[last_name]" type="text" value="">
<span class="error">can't be blank</span>
</div>


I would like to generate html like below to display the message after the label :

<div class="input string required test_last_name field_with_errors">
<label class="string required" for="test_last_name"><abbr title="required">*</abbr> Last name</label><span class="error">can't be blank</span>
<input class="string required" id="test_last_name" name="test[last_name]" type="text" value="">
</div>


I am a newbie, so I apologize if this is a stupid question.

Any help you can give will be much appreciated.

Thanks
Sabbu

Sabbu

unread,
Oct 12, 2015, 4:09:36 PM10/12/15
to SimpleForm

I found the answer and I am posting here so that it might help somebody.

In the simple for configuartion file just put the error tag before input like this :

b.use :error, wrap_with: { tag: :span, class: :error }

b.use :label_input

And add this css on error class:

float:right

Thanks

Sabbu

Reply all
Reply to author
Forward
0 new messages