refactor(js): radio_enabled_submit -> enable_submit_if_checked

This commit is contained in:
simon lehericey 2023-12-19 15:30:12 +01:00
parent 96a8e7888e
commit 2c367846da
4 changed files with 14 additions and 11 deletions

View file

@ -40,10 +40,10 @@
- elsif @state == 'choix'
= form_for :choice,
method: :patch,
data: { controller: 'radio-enabled-submit' },
data: { controller: 'enable-submit-if-checked' },
url: wizard_admin_procedure_groupe_instructeurs_path(@procedure) do |f|
%div{ data: { 'action': "click->radio-enabled-submit#click" } }
%div{ data: { 'action': "click->enable-submit-if-checked#click" } }
= render Dsfr::RadioButtonListComponent.new(form: f,
target: :state,
buttons: [ { label: 'À partir dun champ', value: 'routage_simple', hint: 'crée les groupes en fonction dun champ du formulaire' } ,
@ -54,4 +54,4 @@
%li
= link_to 'Retour', options_admin_procedure_groupe_instructeurs_path(@procedure), class: 'fr-btn fr-btn--secondary'
%li
%button.fr-btn{ disabled: true, data: { 'radio-enabled-submit-target': 'submit' } } Continuer
%button.fr-btn{ disabled: true, data: { 'enable-submit-if-checked-target': 'submit' } } Continuer

View file

@ -1,14 +1,17 @@
import { Controller } from '@hotwired/stimulus';
export class RadioEnabledSubmitController extends Controller {
export class EnableSubmitIfCheckedController extends Controller {
static targets = ['submit'];
declare readonly submitTarget: HTMLButtonElement;
click() {
if (
this.element.querySelectorAll('input[type="radio"]:checked').length > 0
this.element.querySelectorAll('input[type="radio"]:checked').length > 0 ||
this.element.querySelectorAll('input[type="checkbox"]:checked').length > 0
) {
this.submitTarget.disabled = false;
} else {
this.submitTarget.disabled = true;
}
}
}

View file

@ -9,10 +9,10 @@
%h1 Routage à partir dun champ
= form_for :create_simple_routing,
method: :post,
data: { controller: 'radio-enabled-submit' },
data: { controller: 'enable-submit-if-checked' },
url: create_simple_routing_admin_procedure_groupe_instructeurs_path(@procedure) do |f|
%div{ data: { 'action': "click->radio-enabled-submit#click" } }
%div{ data: { 'action': "click->enable-submit-if-checked#click" } }
.notice
Sélectionner le champ à partir duquel créer des groupes dinstructeurs
- buttons_content = @procedure.active_revision.routable_types_de_champ.map { |tdc| { label: tdc.libelle, value: tdc.stable_id } }
@ -24,4 +24,4 @@
%li
= link_to 'Retour', options_admin_procedure_groupe_instructeurs_path(@procedure, state: :choix), class: 'fr-btn fr-btn--secondary'
%li
%button.fr-btn{ disabled: true, data: { disable_with: 'Création des groupes…', 'radio-enabled-submit-target': 'submit' } } Créer les groupes
%button.fr-btn{ disabled: true, data: { disable_with: 'Création des groupes…', 'enable-submit-if-checked-target': 'submit' } } Créer les groupes

View file

@ -4,15 +4,15 @@
%h1.fr-h1 Récupération de dossiers
%h2.fr-h2 Nature des dossiers
= form_with data: { controller: 'radio-enabled-submit' } do |f|
= form_with data: { controller: 'enable-submit-if-checked' } do |f|
- buttons = [{ label: 'des dossiers concernant une collectivité territoriale',
value: 'collectivite',
hint: '(DETR, autres demandes de subvention, consultation du domaine, ...)' },
{ label: 'autre', value: 'autre'}]
%div{ data: { 'action': "click->radio-enabled-submit#click" } }
%div{ data: { 'action': "click->enable-submit-if-checked#click" } }
= render Dsfr::RadioButtonListComponent.new(form: f, target: :nature, buttons: buttons) do
%legend#radio-hint-element-legend.fr-fieldset__legend--regular.fr-fieldset__legend Quel type de dossier souhaitez vous récupérer ?
%button.fr-btn{ disabled: true, data: { 'radio-enabled-submit-target': 'submit' } } Continuer
%button.fr-btn{ disabled: true, data: { 'enable-submit-if-checked-target': 'submit' } } Continuer