refactor(champ): update champ address
This commit is contained in:
parent
df34784d5c
commit
79a65a4847
3 changed files with 22 additions and 7 deletions
|
@ -2,4 +2,15 @@ class EditableChamp::AddressComponent < EditableChamp::EditableChampBaseComponen
|
|||
def dsfr_input_classname
|
||||
'fr-select'
|
||||
end
|
||||
|
||||
def react_props
|
||||
react_input_opts(id: @champ.input_id,
|
||||
class: 'fr-mt-1w',
|
||||
name: @form.field_name(:value),
|
||||
selected_key: @champ.value,
|
||||
items: @champ.selected_items,
|
||||
loader: data_sources_data_source_adresse_path,
|
||||
minimum_input_length: 2,
|
||||
allows_custom_value: true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
= render Dsfr::ComboboxComponent.new form: @form, url: data_sources_data_source_adresse_path, selected: @champ.value, allows_custom_value: true, input_html_options: { name: :value, id: @champ.input_id, class: 'fr-select', describedby: @champ.describedby_id } do
|
||||
= @form.hidden_field :external_id, data: { value_slot: 'value' }
|
||||
= @form.hidden_field :feature, data: { value_slot: 'data' }
|
||||
%react-fragment
|
||||
= render ReactComponent.new "ComboBox/RemoteComboBox", **react_props do
|
||||
= render ReactComponent.new "ComboBox/ComboBoxValueSlot", field: :data, name: @form.field_name(:feature)
|
||||
|
|
|
@ -3,10 +3,6 @@ class Champs::AddressChamp < Champs::TextChamp
|
|||
data.present?
|
||||
end
|
||||
|
||||
def feature
|
||||
data.to_json if full_address?
|
||||
end
|
||||
|
||||
def feature=(value)
|
||||
if value.blank?
|
||||
self.data = nil
|
||||
|
@ -22,6 +18,14 @@ class Champs::AddressChamp < Champs::TextChamp
|
|||
self.data = nil
|
||||
end
|
||||
|
||||
def selected_items
|
||||
if value.present?
|
||||
[{ value:, label: value, data: full_address? ? data : nil }]
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def address
|
||||
full_address? ? data : nil
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue