refactor(champ): update champ drop_down_list

This commit is contained in:
Paul Chavard 2024-05-07 11:25:37 +02:00
parent cb01f15570
commit f0f88ef3f0
No known key found for this signature in database
3 changed files with 12 additions and 2 deletions

View file

@ -23,4 +23,13 @@ class EditableChamp::DropDownListComponent < EditableChamp::EditableChampBaseCom
max_length = 100
@champ.enabled_non_empty_options.any? { _1.size > max_length }
end
def react_props
react_input_opts(id: @champ.input_id,
class: 'fr-mt-1w',
name: @form.field_name(:value),
selected_key: @champ.selected,
items: @champ.enabled_non_empty_options(other: true).map { _1.is_a?(Array) ? _1 : [_1, _1] },
empty_filter_key: @champ.drop_down_other? ? Champs::DropDownListChamp::OTHER : nil)
end
end

View file

@ -18,7 +18,8 @@
%label.fr-label{ for: dom_id(@champ, "radio_option_other") }
= t('shared.champs.drop_down_list.other')
- elsif @champ.render_as_combobox?
= render Dsfr::ComboboxComponent.new form: @form, options: @champ.enabled_non_empty_options(other: true), selected: @champ.selected, input_html_options: { name: :value, id: @champ.input_id, class: select_class_names, describedby: @champ.describedby_id }
%react-fragment
= render ReactComponent.new "ComboBox/SingleComboBox", **react_props
- else
= @form.select :value,
@champ.enabled_non_empty_options(other: true),

View file

@ -285,7 +285,7 @@ class Champ < ApplicationRecord
return if value.nil?
return if value.present? && !value.include?("\u0000")
self.value = value.delete("\u0000")
write_attribute(:value, value.delete("\u0000"))
end
class NotImplemented < ::StandardError