feat(Champ.rna): avoid spaces that breaks API calls
This commit is contained in:
parent
3796210928
commit
abb2fa159c
2 changed files with 13 additions and 1 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.data.blank?, turbo_input_url_value: update_path }, required: @champ.required?, pattern: "W[0-9]{9}", class: "width-33-desktop", maxlength: 10))
|
= @form.text_field(:value, input_opts( id: @champ.input_id, aria: { describedby: @champ.describedby_id }, data: { controller: 'turbo-input format', format: 'deleteSpace', turbo_input_load_on_connect_value: @champ.prefilled? && @champ.value.present? && @champ.data.blank?, turbo_input_url_value: update_path }, required: @champ.required?, pattern: "W[0-9]{9}", class: "width-33-desktop", maxlength: 10))
|
||||||
|
|
||||||
.rna-info{ id: dom_id(@champ, :rna_info) }
|
.rna-info{ id: dom_id(@champ, :rna_info) }
|
||||||
= render 'shared/champs/rna/association', champ: @champ, error: nil
|
= render 'shared/champs/rna/association', champ: @champ, error: nil
|
||||||
|
|
|
@ -4,6 +4,13 @@ export class FormatController extends ApplicationController {
|
||||||
connect() {
|
connect() {
|
||||||
const format = this.element.getAttribute('data-format');
|
const format = this.element.getAttribute('data-format');
|
||||||
switch (format) {
|
switch (format) {
|
||||||
|
case 'deleteSpace':
|
||||||
|
this.on('change', (event) => {
|
||||||
|
const target = event.target as HTMLInputElement;
|
||||||
|
const value = this.deleteSpace(target.value);
|
||||||
|
replaceValue(target, value);
|
||||||
|
});
|
||||||
|
break;
|
||||||
case 'list':
|
case 'list':
|
||||||
this.on('change', (event) => {
|
this.on('change', (event) => {
|
||||||
const target = event.target as HTMLInputElement;
|
const target = event.target as HTMLInputElement;
|
||||||
|
@ -41,16 +48,21 @@ export class FormatController extends ApplicationController {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private deleteSpace(value: string) {
|
||||||
|
return value.replace(/\s*/g, '');
|
||||||
|
}
|
||||||
|
|
||||||
private formatList(value: string) {
|
private formatList(value: string) {
|
||||||
return value.replace(/;/g, ',');
|
return value.replace(/;/g, ',');
|
||||||
}
|
}
|
||||||
|
|
||||||
private formatSIRET(value: string) {
|
private formatSIRET(value: string) {
|
||||||
return value
|
return value
|
||||||
.replace(/[^\d]/gi, '')
|
.replace(/[^\d]/gi, '')
|
||||||
.replace(/^\s*(\d{3})\s*(\d{3})\s*(\d{3})\s*(\d{5})\s*$/gi, '$1 $2 $3 $4')
|
.replace(/^\s*(\d{3})\s*(\d{3})\s*(\d{3})\s*(\d{5})\s*$/gi, '$1 $2 $3 $4')
|
||||||
.trim();
|
.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
private formatIBAN(value: string) {
|
private formatIBAN(value: string) {
|
||||||
return value
|
return value
|
||||||
.replace(/[^\dA-Z]/gi, '')
|
.replace(/[^\dA-Z]/gi, '')
|
||||||
|
|
Loading…
Reference in a new issue