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

Module not always loading correctly #59

Open
HyperC opened this issue Sep 6, 2022 · 2 comments
Open

Module not always loading correctly #59

HyperC opened this issue Sep 6, 2022 · 2 comments

Comments

@HyperC
Copy link

HyperC commented Sep 6, 2022

The module sometimes fails to load correctly, resulting in all the address fields to just show instantly (not the postcode + huisnr autocomplete fields). This happens in 1 out of 10 times or so, using an incognito browser. You need a fresh incognito session to get the error. The error in console:

jQuery.Deferred exception: this.addressFields is not a function TypeError: this.addressFields is not a function at UiClass.onChangeCountry (https://xxxx/nl_NL/Flekto_Postcode/js/form/components/address-autofill-nl.js:76:18)

You then see all fields directly on load:
image

@JelleGe
Copy link

JelleGe commented Sep 30, 2022

We have the same issue on M2.4.4

@HyperC
Copy link
Author

HyperC commented Sep 30, 2022

We temporarily fixed it by creating a mixin on Flekto_Postcode/web/js/form/components/address-autofill-nl.js

onChangeCountry: async function () {
            if (typeof this.addressFields !== 'function') {
                var self = this;
                let setFields = new Promise(function(resolve, reject) {
                    self.addressFields = Registry.async([
                        self.parentName + '.street',
                        self.parentName + '.city',
                        self.parentName + '.postcode',
                        self.parentName + '.region_id_input',
                    ]);

                    setTimeout(function () {
                        resolve();
                    }, 500);
                });

                await setFields;
            }

            this.addressFields(function () { // Wait for address fields to be available.
                const isNl = this.isNl();

                this.childPostcode().visible(isNl);
                this.childHouseNumber().visible(isNl);
                this.childHouseNumberSelect().visible(isNl && this.childHouseNumberSelect().options().length > 0);
                this.toggleFields(!isNl, true);

                if (isNl) {
                    this.resetInputAddress();
                }
            }.bind(this));
        },

It's not the prettiest, but we haven't encountered the issue since.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants