diff --git a/app/components/editable_champ/siret_component/siret_component.html.haml b/app/components/editable_champ/siret_component/siret_component.html.haml index 0bcdcdb47..1970d85cc 100644 --- a/app/components/editable_champ/siret_component/siret_component.html.haml +++ b/app/components/editable_champ/siret_component/siret_component.html.haml @@ -2,7 +2,7 @@ id: @champ.input_id, aria: { describedby: @champ.describedby_id }, placeholder: t(".placeholder"), - data: { controller: 'turbo-input', turbo_input_url_value: champs_siret_path(@champ.id) }, + data: { controller: 'turbo-input', turbo_input_load_on_connect_value: @champ.prefilled? && @champ.value.present? && @champ.etablissement.blank?, turbo_input_url_value: champs_siret_path(@champ.id) }, required: @champ.required?, pattern: "[0-9]{14}", title: t(".title"), diff --git a/app/javascript/controllers/turbo_input_controller.tsx b/app/javascript/controllers/turbo_input_controller.tsx index d194a7f3c..e2ad35db3 100644 --- a/app/javascript/controllers/turbo_input_controller.tsx +++ b/app/javascript/controllers/turbo_input_controller.tsx @@ -4,13 +4,18 @@ import { ApplicationController } from './application_controller'; export class TurboInputController extends ApplicationController { static values = { - url: String + url: String, + loadOnConnect: { type: Boolean, default: false } }; declare readonly urlValue: string; + declare readonly loadOnConnectValue: boolean; connect(): void { this.on('input', () => this.debounce(this.load, 200)); + if (this.loadOnConnectValue) { + this.load(); + } } private load(): void { diff --git a/spec/models/concern/dossier_prefillable_concern_spec.rb b/spec/models/concern/dossier_prefillable_concern_spec.rb index 3ab8f73e9..32a52cad8 100644 --- a/spec/models/concern/dossier_prefillable_concern_spec.rb +++ b/spec/models/concern/dossier_prefillable_concern_spec.rb @@ -6,7 +6,10 @@ RSpec.describe DossierPrefillableConcern do let(:dossier) { create(:dossier, :brouillon, procedure: procedure) } let(:types_de_champ_public) { [] } - subject(:fill) { dossier.prefill!(values); dossier.reload } + subject(:fill) do + dossier.prefill!(values) + dossier.reload + end shared_examples 'a dossier marked as prefilled' do it 'marks the dossier as prefilled' do