Merge pull request #10616 from mfo/US/enhance-siret-champ

Amélioration, ETQ usager je souhaite pouvoir copier/coller un siret contenant des espaces
This commit is contained in:
mfo 2024-07-16 09:50:08 +00:00 committed by GitHub
commit 64811d836a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 4 deletions

View file

@ -1,4 +1,4 @@
= @form.text_field(:value, input_opts(id: @champ.input_id, aria: { describedby: @champ.describedby_id }, data: { controller: 'turbo-input', turbo_input_load_on_connect_value: @champ.prefilled? && @champ.value.present? && @champ.etablissement.blank?, turbo_input_url_value: update_path }, required: @champ.required?, pattern: "[0-9]{14}", class: "width-33-desktop", maxlength: 14))
= @form.text_field(:value, input_opts(id: @champ.input_id, aria: { describedby: @champ.describedby_id }, data: { controller: 'turbo-input format', format: 'siret', turbo_input_load_on_connect_value: @champ.prefilled? && @champ.value.present? && @champ.etablissement.blank?, turbo_input_url_value: update_path }, required: @champ.required?, class: "width-33-desktop"))
.siret-info{ id: dom_id(@champ, :siret_info) }
- if @champ.etablissement.present?
= render EditableChamp::EtablissementTitreComponent.new(etablissement: @champ.etablissement)

View file

@ -11,6 +11,13 @@ export class FormatController extends ApplicationController {
replaceValue(target, value);
});
break;
case 'siret':
this.on('input', (event) => {
const target = event.target as HTMLInputElement;
const value = this.formatSIRET(target.value);
replaceValue(target, value);
});
break;
case 'iban':
this.on('input', (event) => {
const target = event.target as HTMLInputElement;
@ -38,7 +45,12 @@ export class FormatController extends ApplicationController {
private formatList(value: string) {
return value.replace(/;/g, ',');
}
private formatSIRET(value: string) {
return value
.replace(/[^\d]/gi, '')
.replace(/^\s*(\d{3})\s*(\d{3})\s*(\d{3})\s*(\d{5})\s*$/gi, '$1 $2 $3 $4')
.trim();
}
private formatIBAN(value: string) {
return value
.replace(/[^\dA-Z]/gi, '')

View file

@ -3,4 +3,4 @@ en:
attributes:
champs/siret_champ:
hints:
value: "Enter 14 digits, no space. Example : 50000123456789"
value: "Enter 14 digits. Example : 500 0012 345 6789"

View file

@ -3,4 +3,4 @@ fr:
attributes:
champs/siret_champ:
hints:
value: "Saisissez 14 chiffres sans espaces. Exemple : 50000123456789"
value: "Saisissez 14 chiffres. Exemple : 500 001 234 56789"