gpt4 book ai didi

ruby-on-rails - 带有 Bootstrap 的 Rails 简单表单删除验证

转载 作者:行者123 更新时间:2023-12-02 04:24:19 37 4
gpt4 key购买 nike

我有一个带有嵌套 has_many 关联的表单,并且一切正常,除非它加载了以前在那里进行编辑的所有字段,在它们旁边有一个复选标记。我发现它与 simple_form 和 bootstrap 有关,但不确定如何禁用它们。表格代码如下:

<%= simple_form_for ([current_user, @character]), defaults: {label: false} do |f| %>
<div id="tasks">
<%= f.simple_fields_for :character_levels, f.object.character_levels.order(:id) do |l| %>
<%= render '/characters/DnD5e/class_fields', f: l, character: @character %>
<% end %>
<div class="links">
<%= link_to_add_association 'Add Level', f, :character_levels, partial: 'characters/DnD5e/class_fields', render_options: {locals: {character: @character}}, class: "btn btn-primary" %>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<%= f.submit "Save Changes", class: 'btn btn-primary' %>
</div>
<% end %>

继承人的部分:
<div class="row nested-fields">
<div class="col-6">
<%= f.input :character_class_id, collection: CharacterClass.where('game_type_id=? AND (user_id IS ? OR user_id=?)', character.game_type_id, nil, current_user) %>
</div>
<div class="col-4">
<%= f.input :hp, as: :integer %>
</div>
<div class="col-2">
<%= link_to_remove_association '<i class="material-icons">close</i>'.html_safe, f %>
</div>
</div>

这就是它的样子:
enter image description here

想要去掉绿色的勾号

最佳答案

有一个类似的问题,并找到了一个不同的(更好?)解决方案:
config/initializers/simple_form_bootstrap.rb初始值设定项为此包含多个配置:

例如靠近顶部:

  # add validation classes to `input_field`
config.input_field_error_class = 'is-invalid'
config.input_field_valid_class = 'is-valid'

再往下:
  config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
b.optional :minlength
b.optional :pattern
b.optional :min_max
b.optional :readonly
b.use :label
b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
end

它说 valid_class: 'is-valid' 在所有不同的地方将其更改为 '' 应该可以解决问题。不要忘记重新启动您的服务器!

关于ruby-on-rails - 带有 Bootstrap 的 Rails 简单表单删除验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56123254/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com