Merge pull request #10018 from tchak/fix-address-champ

fix(champ): do not reset data on champs without fetch_external_data
This commit is contained in:
Paul Chavard 2024-02-21 09:06:24 +00:00 committed by GitHub
commit 5a8859cd28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 589 additions and 142 deletions

View file

@ -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' }
= @form.hidden_field :feature, value: '', data: { value_slot: 'data' }

View file

@ -44,6 +44,8 @@ export class ComboboxUI implements EventListenerObject {
#allowsCustomValue: boolean;
#limit?: number;
#selectedData: Option['data'] = null;
constructor({
input,
selectedValueInput,
@ -293,7 +295,8 @@ export class ComboboxUI implements EventListenerObject {
private dispatchChange(cb: () => Option['data']): void {
const value = this.#selectedValueInput.value;
const data = cb();
if (value != this.#selectedValueInput.value) {
if (value != this.#selectedValueInput.value || data != this.#selectedData) {
this.#selectedData = data;
for (const input of this.#valueSlots) {
switch (input.dataset.valueSlot) {
case 'value':

View file

@ -282,7 +282,7 @@ class Champ < ApplicationRecord
end
def cleanup_if_empty
if persisted? && external_id_changed?
if fetch_external_data? && persisted? && external_id_changed?
self.data = nil
end
end

View file

@ -3,10 +3,6 @@ class Champs::AddressChamp < Champs::TextChamp
data.present?
end
def feature
''
end
def feature=(value)
return if value.blank?
feature = JSON.parse(value)