简单形式的星号字符“*”Rails 5

时间:2018-01-11 19:23:38

标签: ruby-on-rails ruby simple-form

我正在使用简单形式的gem,输入标签在文本前显示Asterisk“*”,我不需要

像这样的东西: *年 *月 *周 *数量

简单的表单视图:

<%= 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" ] %>

1 个答案:

答案 0 :(得分:1)

这可能是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 %>

Simple Form: Usage

了解详情

最后,如果要为所有简单表单禁用星号标记,可以通过使用以下内容在simple_form.en.yml下创建文件config/locales/来执行此操作:

# 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: ''

simple_form.en.yml on Gituhb

查看更多配置选项