diff --git a/app/helpers/rails_admin/form_builder.rb b/app/helpers/rails_admin/form_builder.rb index baf0877bad..facfc84ea9 100644 --- a/app/helpers/rails_admin/form_builder.rb +++ b/app/helpers/rails_admin/form_builder.rb @@ -38,16 +38,15 @@ def fieldset_for(fieldset, nested_in) end def field_wrapper_for(field, nested_in) - if field.label - # do not show nested field if the target is the origin - unless nested_field_association?(field, nested_in) - @template.content_tag(:div, class: "form-group control-group #{field.type_css_class} #{field.css_class} #{'error' if field.errors.present?}", id: "#{dom_id(field)}_field") do - label(field.method_name, capitalize_first_letter(field.label), class: 'col-sm-2 control-label') + - (field.nested_form ? field_for(field) : input_for(field)) - end + # do not show nested field if the target is the origin + return if nested_field_association?(field, nested_in) + @template.content_tag(:div, class: "form-group control-group #{field.type_css_class} #{field.css_class} #{'error' if field.errors.present?}", id: "#{dom_id(field)}_field") do + if field.label + label(field.method_name, capitalize_first_letter(field.label), class: 'col-sm-2 control-label') + + (field.nested_form ? field_for(field) : input_for(field)) + else + field.nested_form ? field_for(field) : input_for(field) end - else - field.nested_form ? field_for(field) : input_for(field) end end diff --git a/spec/helpers/rails_admin/form_builder_spec.rb b/spec/helpers/rails_admin/form_builder_spec.rb index a95cb9b9ad..e78ba6254c 100644 --- a/spec/helpers/rails_admin/form_builder_spec.rb +++ b/spec/helpers/rails_admin/form_builder_spec.rb @@ -3,6 +3,12 @@ RSpec.describe 'RailsAdmin::FormBuilder', type: :helper do describe '#generate' do before do + RailsAdmin.config Player do + create do + include_all_fields + field :number, :hidden + end + end allow(helper).to receive(:authorized?).and_return(true) (@object = Player.new).save @builder = RailsAdmin::FormBuilder.new(:player, @object, helper, {}) @@ -13,6 +19,10 @@ expect(@builder.generate(action: :create, model_config: RailsAdmin.config(Player))).not_to have_css('.field_with_errors') expect(@builder.generate(action: :create, model_config: RailsAdmin.config(Player))).to have_css('.control-group.error') end + + it 'hidden fields should be wrapper' do + expect(@builder.generate(action: :create, model_config: RailsAdmin.config(Player))).to match('form-group control-group hidden_type number_field') + end end describe '#object_infos' do