找到你要的答案

Q:Display the error message after the label title

Q:在标签标题后显示错误信息

I had the form using the simple form like this:

<%= f.input :last_name %>

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>

Any help will be really appreciated.

Thanks Sabbu

我用这种简单的表格:

<%= f.input :last_name %>

当窗体上有验证错误时,验证错误消息将显示在输入文本框之后:

<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>

我会在标签的HTML生成像下面显示的信息:

<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>

任何帮助将真正感谢。

谢谢 sabbu

answer1: 回答1:

This is a long shot, but try

<%= f.input :last_name as: :required %>

I put 2 and 2 together that this was a ruby project after the fact.

<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>

这是一个很长的镜头,但尝试

<%= f.input :last_name as: :required %>

我把2和2放在一起,这是一个红宝石项目后的事实。

<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>
answer2: 回答2:

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

我找到了答案,我在这里张贴,以便它可以帮助别人。

在简单的配置文件就把错误标记之前输入这样的:

b.使用:错误,wrap_with:{标签::跨类::错误}

b.使用:label_input

对错误类添加CSS:

浮:右

谢谢

sabbu

ruby-on-rails-4  simple-form