Merge pull request #10061 from tchak/fix-adresse-champ
fix(address): nullify data when empty or invalid address is entered
This commit is contained in:
commit
c596b6e37d
2 changed files with 15 additions and 4 deletions
|
@ -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
|
= 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 :external_id, data: { value_slot: 'value' }
|
||||||
= @form.hidden_field :feature, value: '', data: { value_slot: 'data' }
|
= @form.hidden_field :feature, data: { value_slot: 'data' }
|
||||||
|
|
|
@ -3,10 +3,21 @@ class Champs::AddressChamp < Champs::TextChamp
|
||||||
data.present?
|
data.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def feature
|
||||||
|
data.to_json if full_address?
|
||||||
|
end
|
||||||
|
|
||||||
def feature=(value)
|
def feature=(value)
|
||||||
return if value.blank?
|
if value.blank?
|
||||||
|
self.data = nil
|
||||||
|
else
|
||||||
feature = JSON.parse(value)
|
feature = JSON.parse(value)
|
||||||
|
if feature.key?('properties')
|
||||||
self.data = APIGeoService.parse_ban_address(feature)
|
self.data = APIGeoService.parse_ban_address(feature)
|
||||||
|
else
|
||||||
|
self.data = feature
|
||||||
|
end
|
||||||
|
end
|
||||||
rescue JSON::ParserError
|
rescue JSON::ParserError
|
||||||
self.data = nil
|
self.data = nil
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue