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

Stop using update_only to decide to show subform on create #3649

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
2 changes: 1 addition & 1 deletion app/views/rails_admin/main/_form_nested_many.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<a class="<%= (field.active? ? 'active' : '') %> btn btn-info toggler" data-bs-target="<%= form.jquery_namespace(field) %> .collapse" data-bs-toggle="collapse" role="button">
<i class="fas"></i>
</a>
<% unless field.nested_form[:update_only] || !field.inline_add %>
<% if field.inline_add %>
<%= form.link_to_add "<i class=\"fas fa-plus\"></i> #{wording_for(:link, :new, field.associated_model_config.abstract_model)}".html_safe, field.name, { class: 'btn btn-info' } %>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/rails_admin/main/_form_nested_one.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<a class="<%= (field.active? ? 'active' : '') %> btn btn-info toggler" data-bs-target="<%= form.jquery_namespace(field) %> .collapse" data-bs-toggle="collapse" role="button">
<i class="fas"></i>
</a>
<% unless field.nested_form[:update_only] || !field.inline_add %>
<% if field.inline_add %>
<%= form.link_to_add "<i class=\"fas fa-plus\"></i> #{wording_for(:link, :new, field.associated_model_config.abstract_model)}".html_safe, field.name, { class: 'btn btn-info', :'data-add-label' => "<i class=\"fas fa-plus\"></i> #{wording_for(:link, :new, field.associated_model_config.abstract_model)}".gsub("\n", "") } %>
<% end %>
</div>
Expand Down
12 changes: 2 additions & 10 deletions spec/integration/widgets/nested_many_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,13 @@
context 'with nested_attributes_options given' do
before do
allow(FieldTest.nested_attributes_options).to receive(:[]).with(any_args).
and_return(allow_destroy: true, update_only: false)
end

it 'does not show add button when :update_only is true' do
allow(FieldTest.nested_attributes_options).to receive(:[]).with(:nested_field_tests).
and_return(allow_destroy: true, update_only: true)
visit new_path(model_name: 'field_test')
is_expected.to have_selector('.toggler')
is_expected.not_to have_selector('#field_test_nested_field_tests_attributes_field .add_nested_fields')
and_return(allow_destroy: true)
end

it 'does not show destroy button except for newly created when :allow_destroy is false', js: false do
nested_field_tests
allow(FieldTest.nested_attributes_options).to receive(:[]).with(:nested_field_tests).
and_return(allow_destroy: false, update_only: false)
and_return(allow_destroy: false)
visit edit_path(model_name: 'field_test', id: field_test.id)
expect(find('#field_test_nested_field_tests_attributes_0_title').value).to eq('title 1')
is_expected.not_to have_selector('form .remove_nested_fields')
Expand Down