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

Implement Autocomplete for dynamically created DOM elements. #399

Open
dhiliphvenkatesan opened this issue Feb 14, 2023 · 1 comment
Open
Labels
bug Something isn't working

Comments

@dhiliphvenkatesan
Copy link

dhiliphvenkatesan commented Feb 14, 2023

Hi, I am using grapejs for my form builder and it is based on pure javascript and html5. I am trying to implement autocomplete for a particular field. The HTML template in which I have to implement autocomplete is created dynamically.

Example:

    let inputElement = document.createElement('input')
    inputElement.setAttribute('id', 'autocomplete')
    
     const autoCompleteJS = new autoComplete({
        selector: "autocomplete",
        placeHolder: "Search for Food...",
        data: {
            src: ["Sauce - Thousand Island", "Wild Boar - Tenderloin", "Goat - Whole Cut"],
            cache: true,
        },
        resultItem: {
            highlight: true
        },
        events: {
            input: {
                selection: (event) => {
                    const selection = event.detail.selection.value;
                    autoCompleteJS.input.value = selection;
                }
            }
        }
    });

Initially. it is working as autocomplete dropdown but if i click outside of the selected element(refer to the video attached) and comeback to this already selected section, the autocomplete is not working as the dynamic element will be created again with same id "autocomplete". So I have to again initialize the autocomplete by const autoCompleteJS = new autoComplete(configuration).
Is there any way where we can initialize only once and if i change the configuration of autocomplete selector it should work.

GrapesJS.autocomplete.issue.mp4
@dhiliphvenkatesan dhiliphvenkatesan added the bug Something isn't working label Feb 14, 2023
@folknor
Copy link

folknor commented Feb 17, 2023

Is there any way where we can initialize only once and if i change the configuration of autocomplete selector it should work.

No.

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

2 participants