简单形式的星号字符“*”Rails 5
Asterisk character " * " in simple form Rails 5
我使用的是简单形式 gem,输入标签在文本前显示星号“*”,我不需要那个
类似于:
*年
*月
*星期
*数量
简单表单视图:
<%= simple_form_for @tech_evaluation do |f| %>
<%= f.input :year, label: "Año", collection: 2017..2020 %>
<%= f.association :project, label: "Proyecto" %>
<%= f.association :countable_account, label: "Cuenta contable" %>
<%= f.association :item %>
<%= f.input :unit_cost, label: "Costo unidario" %>
<%= f.input :unit, label: "Unidad de medida", collection: [ "C/U" ] %>
这可能与 How to disable asterisk on form's required fields?
重复
如果您只想禁用该表单的星号,请将 defaults: { required: false }
传递给 simple_form_for
:
<%= simple_form_for(@tech_evaluation, defaults: { required: false }) do |f| %>
# ...
或者您甚至可以为单个输入元素禁用它:
<%= f.input :year, label: "Año", collection: 2017..2020, required: false %>
阅读更多内容
最后,如果您想禁用所有简单形式的星号标记,您可以通过在 config/locales/
下创建文件 simple_form.en.yml
来实现,内容如下:
# config/locales/simple_form.en.yml
en:
simple_form:
required:
text: 'required'
mark: '*'
# This will overwrite required text and mark for all simple forms.
# When using html, text and mark won't be used.
# Comment out the line below to return to default settings.
html: ''
查看更多配置选项
我使用的是简单形式 gem,输入标签在文本前显示星号“*”,我不需要那个
类似于: *年 *月 *星期 *数量
简单表单视图:
<%= simple_form_for @tech_evaluation do |f| %>
<%= f.input :year, label: "Año", collection: 2017..2020 %>
<%= f.association :project, label: "Proyecto" %>
<%= f.association :countable_account, label: "Cuenta contable" %>
<%= f.association :item %>
<%= f.input :unit_cost, label: "Costo unidario" %>
<%= f.input :unit, label: "Unidad de medida", collection: [ "C/U" ] %>
这可能与 How to disable asterisk on form's required fields?
重复如果您只想禁用该表单的星号,请将 defaults: { required: false }
传递给 simple_form_for
:
<%= simple_form_for(@tech_evaluation, defaults: { required: false }) do |f| %>
# ...
或者您甚至可以为单个输入元素禁用它:
<%= f.input :year, label: "Año", collection: 2017..2020, required: false %>
阅读更多内容
最后,如果您想禁用所有简单形式的星号标记,您可以通过在 config/locales/
下创建文件 simple_form.en.yml
来实现,内容如下:
# config/locales/simple_form.en.yml
en:
simple_form:
required:
text: 'required'
mark: '*'
# This will overwrite required text and mark for all simple forms.
# When using html, text and mark won't be used.
# Comment out the line below to return to default settings.
html: ''
查看更多配置选项