Fix cart item quantity change rollback #1418
Merged
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.
What?
This is a bug fix.
Context: change the quantity of a cart line item by manually editing the quantity input field value.
Currently, when a manual quantity change fails to succeed (for example, because it is greater than the maximum purchasable quantity), the quantity is reverted to zero in the input field.
It should rollback to the previous value. Not to zero.
This PR fixes this bug.
It is quite simple to see what is the problem in the code:
focus
event handler function,this
is used as a reference to the event target element (jQuery binds the event target element to the event handler function context);this
is not referencing the event target element, as it should, but the enclosing context (Cart class instance)Thus, the fix was also quite simple: only a matter of using a normal function. This way, we have the event target element properly bound to the function's
this
context. ThepreVal
(previous value) variable is properly populated with the input's value.