Fix inputting of decimals like "1.01" in <input type="number"> #31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a bug in Derby where a user cannot enter decimals like "1.01" into an element like this:
As soon as the user has typed, say, "1.0", the input immediately gets reset to "1". This applies to any decimal that starts with "NN.0".
Explanation of the issue
For bindings in
<input type="number" value="{{modelValue}}">
, Derby will automatically turn the user-entered value into a numericmodelValue
.That's done in here:
https://github.com/derbyjs/derby/blob/57d28637e8489244cc8438041e6c61d9468cd344/lib/documentListeners.js#L23-L25
https://github.com/derbyjs/derby/blob/57d28637e8489244cc8438041e6c61d9468cd344/lib/documentListeners.js#L99-L102
However, the
expression.set(binding.context, value)
in the second link eventually results inDynamicAttribute.update
getting called.That function does do a check to skip updating the property if it doesn't need to be changed. However, because the HTML input
value
property is a string, the code stringifies1
into'1'
, then compares it to the user-entered value'1.0'
. The two are different, so the code sets the value to'1'
, resulting in the observed bug.The fix
Special-case updates to the
<input type="number">
value property to do a comparison based on the numeric value.