feat(dossier): use new combobox on champ adresse
This commit is contained in:
parent
ae450a2d2b
commit
89582d2e09
3 changed files with 14 additions and 12 deletions
|
@ -1,2 +1,2 @@
|
|||
class EditableChamp::AddressComponent < EditableChamp::ComboSearchComponent
|
||||
class EditableChamp::AddressComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,11 +1,2 @@
|
|||
- render_parent
|
||||
|
||||
= @form.hidden_field :value
|
||||
= @form.hidden_field :external_id
|
||||
|
||||
= react_component("ComboAdresseSearch",
|
||||
required: @champ.required?,
|
||||
id: @champ.input_id,
|
||||
describedby: @champ.describedby_id,
|
||||
**react_combo_props,
|
||||
)
|
||||
= render Dsfr::ComboboxComponent.new form: @form, name: :value, url: data_sources_data_source_adresse_path, selected: @champ.value, id: @champ.input_id, class: 'fr-select', describedby: @champ.describedby_id do
|
||||
= @form.hidden_field :external_id, data: { value_slot: 'value' }
|
||||
|
|
11
app/controllers/data_sources/adresse_controller.rb
Normal file
11
app/controllers/data_sources/adresse_controller.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
class DataSources::AdresseController < ApplicationController
|
||||
def search
|
||||
if params[:q].present? && params[:q].length > 3
|
||||
response = Typhoeus.get("#{API_ADRESSE_URL}/search", params: { q: params[:q], limit: 10 })
|
||||
result = JSON.parse(response.body, symbolize_names: true)
|
||||
render json: result[:features].map { { label: _1[:properties][:label], value: _1[:properties][:label] } }
|
||||
else
|
||||
render json: []
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue