Allow negative numbers when using decimals input mask

Created on 30 April 2024, 7 months ago
Updated 11 July 2024, 4 months ago

<code><code>

Problem/Motivation

We're using the currency input mask on a custom composite element that includes an 'adjustment' field that should allow negative decimals.

The JavaScript library providing functionality, Inputmask, has support for negative values and even recently fixed an edge-case bug with them for currency https://www.drupal.org/project/webform/issues/3207724 β†’ .

Steps to reproduce

Put a decimal input mask on a textfield, put a negative value in it, and try to submit the webform.

You will not be able to, and the message "Decimal field is not in the right format".

Proposed resolution

"'alias': 'decimal'" => [
    'title' => $this->t('Decimal'),
    'example' => '1.234',
    'pattern' => '^\d+(\.\d+)?$',
],

To use pattern: ^(-\d+(\.\d+)?)$

Remaining tasks

Decide if we want this, have someone double-check the regex, and make a patch.

If not we can document using hook_webform_element_input_masks() to add a new input mask or hook_webform_element_input_masks_alter() to change the existing currency one (if we still refer to moduleHandler invoke and alter as hooks!).

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

6.2

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada nancyHebert

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024