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

94639 deselect bug fix #571

Merged
merged 4 commits into from
Mar 4, 2023
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
14 changes: 10 additions & 4 deletions app/assets/javascripts/fae/form/inputs/_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,17 @@ Fae.form.select = {
})
});

// Add actions to wraper
$deselect_all_action.insertAfter($chosen);
// prevent multiple deselect all actions from being added when nested forms are generated
if ($('.multiselect-action_wrap').length === 0) {
// Add actions to wraper
$deselect_all_action.insertAfter($chosen);
}

// Add special "Select All" option and notify Chosen of new option
addSelectAllOption($element)
// prevent multiple 'SELECT ALL' options from being added when nested forms are generated
if ($element[0].options[0].value != select_all_value) {
// Add special "Select All" option and notify Chosen of new option
addSelectAllOption($element);
}

// Mark label wrapper as having multiselect actions for styling
$label.addClass('has-multiselect-actions');
Expand Down
2 changes: 2 additions & 0 deletions spec/dummy/app/views/admin/wines/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
= fae_input f, :food_pairing_en
= fae_input f, :food_pairing_zh
= fae_input f, :food_pairing_ja
// need for testing
= fae_association f, :releases

- if params[:action] == 'edit'
section.content#oregon_winemakers_section
Expand Down
23 changes: 23 additions & 0 deletions spec/features/form_helpers/fae_multiselect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,27 @@
expect(page).to have_content('Bathroom Reader Monthly')
end

scenario 'should only display a single "de-select all" option after rendering nested form', js: true do
wine = FactoryBot.create(:wine)
release = FactoryBot.create(:release, name: 'testy mctest')
release = FactoryBot.create(:release, name: 'testy mctest 2')

admin_login
visit edit_admin_wine_path(wine)

click_link 'Add Oregon Winemaker'
expect(page).to have_css('form#new_winemaker')


group = find 'div.select'
group.click
within(group) do
find('li', text: 'testy mctest 2').click
end

eventually {
expect(page).to have_selector('.js-multiselect-action-deselect_all', count: 1)
}
end

end