Skip to content

Commit 817e34b

Browse files
committed
Merge pull request #2409 from aquajach/master
Changing a field's type shouldn't position it at the bottom
2 parents ab86b2f + 651e3cc commit 817e34b

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

lib/rails_admin/config/has_fields.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ def field(name, type = nil, add_to_section = true, &block)
2121
elsif type && type != (field.nil? ? nil : field.type)
2222
if field
2323
properties = field.properties
24-
_fields.delete(field)
24+
field = _fields[_fields.index(field)] = RailsAdmin::Config::Fields::Types.load(type).new(self, name, properties)
2525
else
2626
properties = abstract_model.properties.detect { |p| name == p.name }
27+
field = (_fields << RailsAdmin::Config::Fields::Types.load(type).new(self, name, properties)).last
2728
end
28-
field = (_fields << RailsAdmin::Config::Fields::Types.load(type).new(self, name, properties)).last
2929
end
3030

3131
# If field has not been yet defined add some default properties

spec/rails_admin/config/has_fields_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,20 @@
3535
end
3636
expect(RailsAdmin.config(Team).fields.detect { |f| f.name == :players }.properties).not_to be_nil
3737
end
38+
39+
it 'does not change the order of existing fields, if some field types of them are changed' do
40+
original_fields_order = RailsAdmin.config(Team).fields.map(&:name)
41+
42+
RailsAdmin.config do |config|
43+
config.model Team do
44+
configure :players, :enum do
45+
enum { [] }
46+
end
47+
48+
configure :revenue, :integer
49+
end
50+
end
51+
52+
expect(RailsAdmin.config(Team).fields.map(&:name)).to eql(original_fields_order)
53+
end
3854
end

0 commit comments

Comments
 (0)