繁体   English   中英

如何将我的错误消息与Ruby on Rails的Simple_form对齐?

[英]how do I align my error message with Simple_form for Ruby on Rails?

目前,我的表单看起来像这样,并显示一条错误消息(“名称”为必填字段):

在此处输入图片说明

但是我想将“不能为空”错误与“名称”放在一起,如下所示:

在此处输入图片说明

通过使用以下代码从默认的引导程序Simple_form类进行更改,我为自己在“名称”标签和错误上提供了更多的自由:

<%= f.input :name, :required => true, :label_html => { :class => 'edit_form_titles' }, :error_html => { :class => 'cant_be_blank'} %>

对于这些类,我的css是:

  .edit_form_titles{
  display: block;
  margin-bottom: 0px;
  color: #333333;
  }

  .cant_be_blank{
  font-size:12px;
  }

如我所描述的,关于如何在错误名称旁边对齐错误消息的任何想法? 谢谢你的帮助。

我设法使错误显示在输入框上方的标签中。

在下面的代码中,我给我的错误一个类,可以将其格式化为位置等,但是在输入框下始终有一个空白div或其他内容,这使其他输入框脱离了关节。

<%= f.input :name, :required => true, :label_html => { :class => 'edit_form_titles' }, :error_html => { :class => 'cant_be_blank'} %>

在我的初始值设定项/simple_form.rb中,有:

  config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
    b.use :html5
    b.use :placeholder
    b.use :label
    b.wrapper :tag => 'div', :class => 'controls' do |input|
      input.use :input
      input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
      input.use :hint,  :wrap_with => { :tag => 'p', :class => 'help-block' }
    end
  end

我将其更改为:

 config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
    b.use :html5
    b.use :placeholder
    b.wrapper :tag => 'div', :class => 'label-error' do |input|
      b.use :label
      b.use :error, :wrap_with => { :tag => 'span', :class => 'help-block' }
    end
    b.wrapper :tag => 'div', :class => 'controls' do |ba|
      ba.use :input
      ba.use :hint,  :wrap_with => { :tag => 'p', :class => 'help-block' }
    end
  end

这消除了输入框下的空白空间,我可以设置cant_be_blank类的格式,以便文本恰好出现在标签中文本的旁边。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM