Skip to content

Commit

Permalink
Merge pull request #2737 from tmesquita/nested-attributes-form-fix
Browse files Browse the repository at this point in the history
fixes 'Cannot set property '_renderItem' of undefined' when adding a nested resource
  • Loading branch information
mshibuya authored Oct 29, 2016
2 parents b92a4d1 + ca0510e commit 326ee71
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
15 changes: 7 additions & 8 deletions app/assets/javascripts/rails_admin/ra.filtering-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,21 @@
select: null,

_create: function() {
var filtering_select;
var filtering_select = this.element.siblings(
'[data-input-for="' + this.element.attr('id') + '"]'
);

// When using the browser back and forward buttons, it is possible that
// the autocomplete field will be cached which causes duplicate fields
// to be generated.
if (this.element.is(':visible')) {
if (filtering_select.size() > 0) {
this.input = filtering_select.children('input');
this.button = filtering_select.children('.input-group-btn');
} else {
this.element.hide();
filtering_select = this._inputGroup(this.element.attr('id'));
this.input = this._inputField();
this.button = this._buttonField();
} else {
filtering_select = this.element.siblings(
'[data-input-for="' + this.element.attr('id') + '"]'
);
this.input = filtering_select.children('input');
this.button = filtering_select.children('.input-group-btn');
}

this._setOptionsSource();
Expand Down
8 changes: 5 additions & 3 deletions spec/integration/basic/edit/rails_admin_basic_edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@

it 'shows associated objects' do
is_expected.to have_selector '#fan_team_ids' do |select|
expect(select[0]).to have_selector 'option[selected="selected"]'
expect(select[1]).not_to have_selector 'option[selected="selected"]'
expect(select[2]).not_to have_selector 'option[selected="selected"]'
options = select.all 'option'

expect(options[0]['selected']).to eq 'selected'
expect(options[1]['selected']).to eq nil
expect(options[2]['selected']).to eq nil
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/integration/config/edit/rails_admin_config_edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,15 @@ class HelpTest < Tableless
expect(@record.nested_field_tests[0].title).to eq('nested field test title 1 edited')
end

it 'works with nested has_many', js: true do
@record = FactoryGirl.create :field_test
visit edit_path(model_name: 'field_test', id: @record.id)

find('#field_test_nested_field_tests_attributes_field .add_nested_fields').click

expect(page).to have_selector('.fields.tab-pane.active', visible: true)
end

it 'is optional for has_one' do
@record = FactoryGirl.create :field_test
visit edit_path(model_name: 'field_test', id: @record.id)
Expand Down

0 comments on commit 326ee71

Please sign in to comment.