Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hidden indent #3278

Merged
merged 4 commits into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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