Closed danielabar closed 2 months ago
Note after the merge -- we'll want to change the error message from "Quantity is not a number" to "Quantity is not a number -- note: commas are not allowed" -- because anyone who puts commas in will take umbrage at the idea that 1,300 is not a number. Not incredibly urgent - will make a good first issue.
@danielabar: Your PR 3373 numeric input safari
is part of today's Human Essentials production release: 2024.04.28.
Thank you very much for your contribution!
Resolves #3373
Description
This changes the item quantity field to be text rather than numeric. Safari allows entry of non-numeric characters, but then submits a blank value. When combined with the feature that the system doesn't associate items when either the name or quantity is left blank (due to use of custom
reject_if
proc option onaccepts_nested_attributes_for
inItemizable
concern ), this creates confusion for Safari users because their donation will be saved without the item they added. (the server gets a blank quantity field and assumes they didn't want to add an item).It was decided to resolve this by converting the item field to text. This ensures that for all browsers, whatever value the user types in gets submitted, and then the Item numeric validation runs server side, which will report back to the user if the value they entered isn't numeric.
Note that other options were considered including modifying the Itemizable concern, this may become future work.
Changing the input type had some knock-on effects that were fixed:
input[type=number]
as selector, this was modified to use a data dash attribute.valueAsNumber
which only works when the field is numeric, for text this returnsNaN
. Fixed to useparseInt
.create.js.erb
also usesinput[type=number]
selector, was fixed in the same way as barcode js..numeric
as a selector, which is. a class added bysimple_form
on numeric inputs. As this class is no longer added, these tests started breaking, fixed to use the data dash selector.numeric
css class is also used for styling, added the data dash attribute to have the same style. Intentionally did not remove the existingnumeric
from css because there are other uses of it.spec/system/purchase_system_spec.rb
was failing even before my changes - because it expects a quantity field to be updated, but that happens via JS and the existing way the test was written wasn't waiting for that, fixed.Type of change
Bug fix (non-breaking change which fixes an issue)
How Has This Been Tested?
Maintained existing system tests, and added new system test to verify entering a non numeric value in quantity field will error.
Can also exercise this manually - try in Safari:
1,000
Screenshots
From Safari: