Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkout: ZIP code in shipping address form already validated on page load #7724

Closed
ktruehl opened this issue Dec 8, 2016 · 13 comments
Closed
Labels
bug report Component: Checkout Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Progress: needs update

Comments

@ktruehl
Copy link

ktruehl commented Dec 8, 2016

When loading the checkout page and no shipping address has been saved yet (for example during guest checkout), the ZIP code field will already show as having failed the validation ("this is a required field") without any user interaction.

Preconditions

  1. Magento CE 2.1.1

Steps to reproduce

  1. make sure no user is logged in
  2. put articles into cart
  3. proceed to checkout

Expected result

  1. Once the checkout page finishes loading, all text fields of the shipping address form should be empty and not yet validated.

Actual result

  1. All fields are empty, but the ZIP code field is already validated and shows a red frame and "this is a required field" message.
    screenshot-qp2-local dev refusion com 2016-12-08 11-08-28

Investigation

The problem seems to be that the field value is programmatically set before the page has finished loading. We haven't found out what causes this to happen. However, the problem is that the new value for the field is undefined. Then previous value is an empty string. The equalityComparer for the ZIP code field is the valuesArePrimitiveAndEqual(a, b) method (/lib/web/knockoutjs/knockout.js). So the method isDifferent: function(oldValue, newValue) (/lib/web/knockoutjs/knockout.js) returns true.

Workaround

For all practical purposes we are fine with the empty string being considered equal to null or undefined, so we can replace the equalityComparer property of the ZIP code field. We can do this by overriding the initObservable() method in /vendor/magento/module-ui/view/base/web/js/form/element/post-code.js. See attached patch.
avoid-premature-zip-code-validation-vendor_magento_module-ui_view_base_web_js_form_element_post-code.diff.zip

@parthpatel147
Copy link

Thanks. Code is working.

@arunu
Copy link
Member

arunu commented Dec 26, 2016

Thanks for the fix

@PieterCappelle
Copy link
Contributor

Hopefully this will be added to 2.1.4 or 2.2.

@bh-ref
Copy link
Contributor

bh-ref commented Feb 21, 2017

issue is still present in 2.1.4

@vphat28
Copy link

vphat28 commented Mar 7, 2017

thanks for the fix, you saved me a lot

@rohitgoel
Copy link

that works perfect thanks it really saves a lot of time .

@gweeble
Copy link

gweeble commented Apr 18, 2017

Would it not be easier fto provide in a switch at store level in the configuration for the Postcode prepopulation of "*", because it is causing all sorts of failed transactions for us and no doubt other webstore devs.

Many thanks,

Guy

@lxgiang90
Copy link

Thanks you very very much. Code working ! @ktruehl

@smoskaluk
Copy link

@ktruehl May please let me know if this issue relevant for latest release of Magento 2?

@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Sep 18, 2017
@MaximilianSchwarz
Copy link

The problem also exist in the newest Magento 2.2.5.

@SAN1TAR1UM
Copy link

Issue still exists in 2.2.6

@PathToLife
Copy link
Member

PathToLife commented Jan 7, 2019

Can also reproduce..

Still exists in 2.3.0. Just have to set a postcode in "Default Tax Destination Calculation"

Which is set here:
http://Base_url/admin/admin/system_config/edit/section/tax/
postcode set here

Use Xdebug in any active shipping module on calling RateRequest->getDestPostcode(). We observe that:

Magento\Quote\Model\Quote\Address\RateRequest->$_data['dest_postcode'] = Default Tax Destination Calculation

@PathToLife
Copy link
Member

#18630

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Checkout Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Progress: needs update
Projects
None yet
Development

No branches or pull requests