Rails:如何在表单的必填字段上禁用星号? [英] Rails: How to disable asterisk on form's required fields?

查看:32
本文介绍了Rails:如何在表单的必填字段上禁用星号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我添加必需"属性时
对于 html 输入字段,Rails 在标签前预置一个星号 (*).

有谁知道如何防止这种情况发生?

出于某种原因,Rails 对此进行了转换:

<%= f.input :Company, :input_html =>{:值=>"", :id =>"company_name"}, :label =>公司名称"%>

进入这个:

<label for="company_name" class="string required"><abbr title="required">*</abbr>公司名称</label><input type="text" value="" size="50" required="required" name="lead[Company]" id="company_name" class="string required">

我不喜欢它把所有东西都包装在一个 DIV 中并向派对添加一个 ABBR 元素.

我怎样才能防止这种情况发生?

解决方案

在 config/initializers/simple_form.rb 添加这一行:

config.label_text = lambda { |label, required|#{标签}" }

When I add the 'Required' attribute
to html input fields, Rails pre-pends an asterisk (*) before the label.

Does anyone know how to prevent this?

For some reason Rails transforms this:

<%= f.input :Company, :input_html => {:value => "", :id => "company_name"}, :label => "company name" %>

into this:

<div class="input string required">
    <label for="company_name" class="string required">
    <abbr title="required">*</abbr> company name</label>
    <input type="text" value="" size="50" required="required" name="lead[Company]" id="company_name" class="string required">
</div>

I don't like that it wraps everything in a DIV and adds an ABBR element to the party.

How can I prevent this?

解决方案

In config/initializers/simple_form.rb add this line:

config.label_text = lambda { |label, required| "#{label}" }

这篇关于Rails:如何在表单的必填字段上禁用星号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆