Skip to content

Commit

Permalink
Merge pull request #3278 from jubilee2/fix-hidden-indent
Browse files Browse the repository at this point in the history
Fix hidden indent
  • Loading branch information
mshibuya authored Oct 3, 2020
2 parents bd950c2 + 01e1700 commit a401695
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
17 changes: 8 additions & 9 deletions app/helpers/rails_admin/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions spec/helpers/rails_admin/form_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, {})
Expand All @@ -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
Expand Down

0 comments on commit a401695

Please sign in to comment.