Merge pull request #5489 from betagouv/allow-deselecting-all-checkbox-items

Usager : correction d'un problème où décocher toutes les cases d'une liste n'enregistrait pas les changements
This commit is contained in:
Pierre de La Morinerie 2020-08-27 11:30:10 +02:00 committed by GitHub
commit 0570692d4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View file

@ -1,10 +1,11 @@
- if champ.options? - if champ.options?
- if champ.render_as_checkboxes? - if champ.render_as_checkboxes?
- champ.enabled_non_empty_options.each do |option| = form.collection_check_boxes(:value, champ.enabled_non_empty_options, :to_s, :to_s) do |b|
.editable-champ.editable-champ-checkbox .editable-champ.editable-champ-checkbox
%label = b.label do
= form.check_box :value, { multiple: true, checked: champ&.value&.include?(option) }, option, nil = b.check_box({ multiple: true, checked: champ&.value&.include?(b.value) })
= option = b.text
- else - else
= form.select :value, = form.select :value,
champ.options, champ.options,

View file

@ -72,6 +72,10 @@ describe 'shared/dossiers/edit.html.haml', type: :view do
it 'renders the list as checkboxes' do it 'renders the list as checkboxes' do
expect(subject).to have_selector('input[type=checkbox]', count: enabled_options.count) expect(subject).to have_selector('input[type=checkbox]', count: enabled_options.count)
end end
it 'adds an extra hidden input, to send a blank value even when all checkboxes are unchecked' do
expect(subject).to have_selector('input[type=hidden][value=""]')
end
end end
context 'when the list is long' do context 'when the list is long' do