Merge pull request #9570 from demarches-simplifiees/etq-usager-je-peux-saisir-des-nombres-negatifs

Correction : ETQ usager je peux saisir des nombres négatifs
This commit is contained in:
Colin Darie 2023-10-09 07:27:40 +00:00 committed by GitHub
commit de71cb32d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 4 deletions

View file

@ -1 +1 @@
= @form.text_field(:value, input_opts(id: @champ.input_id, aria: { describedby: @champ.describedby_id }, pattern: "[0-9]*", inputmode: :numeric, required: @champ.required?, data: { controller: 'format', format: :integer }))
= @form.text_field(:value, input_opts(id: @champ.input_id, aria: { describedby: @champ.describedby_id }, pattern: "-?[0-9]*", inputmode: :numeric, required: @champ.required?, data: { controller: 'format', format: :integer }))

View file

@ -1 +1 @@
= @form.text_field(:value, input_opts(id: @champ.input_id, aria: { describedby: @champ.describedby_id }, placeholder: @champ.libelle, required: @champ.required?, pattern: "[0-9]*", inputmode: :decimal))
= @form.text_field(:value, input_opts(id: @champ.input_id, aria: { describedby: @champ.describedby_id }, placeholder: @champ.libelle, required: @champ.required?, pattern: "-?[0-9]*", inputmode: :decimal))

View file

@ -44,7 +44,7 @@ export class FormatController extends ApplicationController {
}
private formatInteger(value: string) {
return value.replace(/[^\d]/g, '');
return value.replace(/[^-?\d]/g, '');
}
private formatDecimal(value: string) {
@ -54,6 +54,6 @@ export class FormatController extends ApplicationController {
const decimalSeparator =
value.lastIndexOf(',') > value.lastIndexOf('.') ? ',' : '.';
return value.replace(new RegExp(`[^\\d${decimalSeparator}]`, 'g'), '');
return value.replace(new RegExp(`[^-?\\d${decimalSeparator}]`, 'g'), '');
}
}

View file

@ -185,6 +185,11 @@ describe 'The user' do
champ_value_for('nombre entier') == '300'
}
fill_in('nombre entier', with: '-256')
wait_until {
champ_value_for('nombre entier') == '-256'
}
fill_in('nombre décimal', with: '123 456,78')
wait_until {
champ_value_for('nombre décimal') == '123456.78'
@ -194,6 +199,11 @@ describe 'The user' do
wait_until {
champ_value_for('nombre décimal') == '1234.56'
}
fill_in('nombre décimal', with: '-1,234.56')
wait_until {
champ_value_for('nombre décimal') == '-1234.56'
}
end
scenario 'extends dossier experation date more than one time, ', js: true, retry: 3 do