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

how to prevent form submission when a link is selected. #119

Open
cojaco opened this issue Jul 24, 2024 · 2 comments
Open

how to prevent form submission when a link is selected. #119

cojaco opened this issue Jul 24, 2024 · 2 comments

Comments

@cojaco
Copy link

cojaco commented Jul 24, 2024

Hi,

Thank you for this nifty Plugin, it works great for me. But there is one thing I cant't manage.

I have different groups for autocompletion search items. One Group containing Links, and I managed to wrap them inside the

elements.

Now, I wan't to follow this Link if I select one of these Items, how can I do that?

@cojaco
Copy link
Author

cojaco commented Jul 25, 2024

Sorry, it was easier than expected.

onSelect: (item, inputfield) => {
if (item.link) window.location.href = item.link;
inputfield.value = item.label
},

@cojaco
Copy link
Author

cojaco commented Jul 25, 2024

hmm it only worked for mouse clicked selections, not for enter key events.

I had to modify the handleEnterKey function a little bit to make it work.

function handleEnterKey(ev) {
            if (selected !== 'undefined') {
                if (preventSubmit === 'OnSelect' /* 2 */) {
                    ev.preventDefault();
                }
                suppressAutocomplete = true;
                try {
                    settings.onSelect(selected, input);
                }
                finally {
                    suppressAutocomplete = false;
                }
                clear();
            }
            if (preventSubmit === 1 /* Always */) {
                ev.preventDefault();
            }
        }

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

1 participant