feat(champ.siret): allow copy/paste from web
This commit is contained in:
parent
6dc8496d3d
commit
23d9c62245
4 changed files with 16 additions and 4 deletions
|
@ -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)
|
||||
|
|
|
@ -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, '')
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue