fix(editable_champ): can enter negative integer number

This commit is contained in:
Eric Leroy-Terquem 2023-10-06 14:27:50 +02:00
parent 4750e4a4bf
commit e17d694b30
3 changed files with 7 additions and 2 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

@ -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) {

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'