Problem/Motivation
We're using the currency input mask on a custom composite element that includes an 'adjustment' field that should allow negative amounts of dollars.
The JavaScript library providing functionality, Inputmask, has support for negative values and even recently fixed an edge-case bug with them.
Steps to reproduce
Put a currency 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 "Please match the requested format." will point to your field.
Proposed resolution
In `webform/src/Plugin/WebformElement/TextBase.php` change:
$input_masks = [
"'alias': 'currency'" => [
'title' => $this->t('Currency'),
'example' => '$ 9.99',
'pattern' => '^\$ [0-9]{1,3}(,[0-9]{3})*.\d\d$',
],
to use the pattern: ^[-]?\$ [0-9]{1,3}(,[0-9]{3})*.\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
None.
API changes
None?
Data model changes
None.

Comments
Comment #2
jrockowitz commentedI think changing the behavior of the currency input mask to support negative numbers would cause problems for people who don't want a negative currency value submitted.
We could add a "currency (-)" and "currency (+/-)" inputs mask aliases and change the title of the current currency mask alias to "Currency (+)".
Any changes should also be applied to Webform 8.x-5.x.
Comment #3
mlncn commentedComment #4
mlncn commentedHere's a patch giving us three total currency masks leaving the original unchanged except for the name— this applies cleanly against both 6.x and 8.x-5.x.
Comment #5
jrockowitz commentedMy online feedback is to avoid abbreviations and change 'currency_pos_neg' to 'currency_positive_negative'.
Comment #6
mlncn commentedUpdated patch without abbreviations— and two more places that need to account for the two new masks.
Comment #7
paulocsAdding tests for the new feature.
Comment #8
marcusvsouza commentedPatch applies properly and works fine.
Comment #9
jrockowitz commentedThere seems to be a bug where two dashes are being displayed when there is a default value. When the input has no default value, it works as expected. I tried upgrading the InputMask library, and that did not help.
I think we need to use the
allowMinus: trueoption. When I tried using these options, a negative number was optional, and plus signs were not supported. We might need to only provide a negative number input mask.@see https://stackoverflow.com/questions/40762041/jquery-inputmask-decimal-va...
Please make sure test changes via the web browser and not rely on the automated test.
Comment #10
paulocsI'll work on it.
Comment #11
paulocsNew patch that fixes #9.
Comment #12
marcusvsouza commentedThe "-" do not appears when the negative mask is selected, and is not possible insert numbers without manually enter the negative signal.
Comment #13
marcusvsouza commentedThe problem where it was not possible to enter numbers without manually entering the character "-" has been solved.
Comment #14
jrockowitz commentedComment #15
jrockowitz commentedThe only problem is a positive number can be submitted when only a negative input format is assigned.
Please review the attached patch and interdiff.
Comment #16
marcusvsouza commentedTested, worked as expected.
Comment #17
jrockowitz commented