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

ReferenceError: regeneratorRuntime is not defined #312

Closed
8 tasks
MikeAlhayek opened this issue Jan 30, 2022 · 1 comment
Closed
8 tasks

ReferenceError: regeneratorRuntime is not defined #312

MikeAlhayek opened this issue Jan 30, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@MikeAlhayek
Copy link

MikeAlhayek commented Jan 30, 2022

First of all, thank you very much for making this nice plugin public. I encountered an issue when trying to fetch the data using fetch.

  • System Information

    • Browser type and version: Google Chrome Version 97.0.4692.99 (Official Build) (64-bit)
    • OS type and version Windows 10
    • WINDOWS: be sure to indicate which terminal you're using -- (i.e., cmd.exe, powershell, git- bash, cygwin, Ubuntu via windows subsystem for linux, etc...)
    • Node version (IF applicable)
      • Any error messages that may be in the console where you ran npm start
    • Any error messages in the JS console
  • Describe the bug
    I initialize the plugin line this

document.addEventListener('DOMContentLoaded', () => {

    var selector = document.querySelector('.customer-autocomoplete');

    selector.addEventListener("selection", function (event) {
        console.log(event.detail);
    });

    new autoComplete({
        selector: () => {
            return selector;
        },
        placeHolder: selector.getAttribute('data-placeholder') || '',
        threshold: 3,
        data: {
            src: async (query) => {
                try {
                    var url = selector.getAttribute('data-fetch-url').trim('/') + `?q=${query}`
                   
                    if (url) {
                        var response = await fetch(url);

                        return await response.json();
                    }
                    return [];
                } catch (error) {
                    return error;
                }
            },
            cache: false,
            keys: ['DisplayText']
        }
    });

});

The above code return the following error

ReferenceError: regeneratorRuntime is not defined

I changed the code to code below, but that also give me the following exception

Uncaught (in promise) TypeError: data.src(...).then is not a function

document.addEventListener('DOMContentLoaded', () => {

    var selector = document.querySelector('.customer-autocomoplete');

    selector.addEventListener("selection", function (event) {
        // "event.detail" carries the autoComplete.js "feedback" object
        console.log(event.detail);
    });

    new autoComplete({
        selector: () => {
            return selector;
        },
        placeHolder: selector.getAttribute('data-placeholder') || '',
        threshold: 3,
        data: {
            src: (query) => {
                try {
                    // Fetch Data from external Source
                    var url = selector.getAttribute('data-fetch-url').trim('/') + `?q=${query}`

                    console.log(url, 'fetch url');
                   
                    if (url) {
                        var response = fetch(url);

                        return response.json();
                    }
                    return [];
                } catch (error) {
                    return error;
                }
            },
            cache: false,
            keys: ['contentItemId']
        }
    });
});
@MikeAlhayek MikeAlhayek added the bug Something isn't working label Jan 30, 2022
@MikeAlhayek
Copy link
Author

I changed the code to this and it worked

data: {
            src: function (query) {
                var url = selector.getAttribute('data-fetch-url').trim('/') + `?q=${query}`

                return fetch(url).then(data => data.json());
            },
            cache: false,
            keys: ['DisplayText']
        },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant