fix(champ): do not reset data on champs without fetch_external_data
This commit is contained in:
parent
6ef969a7d9
commit
702b9dd8b3
8 changed files with 589 additions and 142 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
|
||||
= @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' }
|
||||
|
|
|
@ -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':
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue