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

Focusing element with 'select' mode and empty whitelist causes Uncaught TypeError #1437

Open
asask-infosys-dx opened this issue Feb 4, 2025 · 2 comments
Labels

Comments

@asask-infosys-dx
Copy link

In case of initializing Tagify in ‘select’ mode with an empty whitelist, an Uncaught TypeError occurs when the input element is focused.

Here is the code to reproduce the issue:

new Tagify(document.querySelector('input'), {
    mode: 'select',
    whitelist: [],
});

The error message is as follows:

Uncaught TypeError: Cannot read properties of undefined (reading 'closest')
    at Y.onDoubleClickScope
    at Y.onClickScope

It seems that the cause of this error is that e.target is undefined in the first line of the onDoubleClickScope method, specifically at e.target.closest.

onDoubleClickScope(e) {
  var tagElm = e.target.closest('.' + this.settings.classNames.tag),

It would be greatly appreciated if this issue could be resolved.

@yairEO
Copy link
Owner

yairEO commented Feb 4, 2025

I advise you, as the author of your code, to handle this in your own app:

  1. if the whitelist will remain empty, and you know this is the case, "lock" the tagify field by setting it to be disabled.
  2. if the whitelist is being fetched and this takes time, then "lock" the field while this is happening and unlock it once the whitelist has been set.

Regardless, I will handle this edge case so no error is thrown.

Thanks for reporting!

@yairEO yairEO added the Bug label Feb 4, 2025
@asask-infosys-dx
Copy link
Author

Thank you very much for the reply and the advice.

In my app, the whitelist is retrieved after a user perform a specific action.
So I will "lock" the tagify field with disabled setting as you advised.

As a big fan of your outstanding module, I would be very happy to see it achieve even greater functionality :-)

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

No branches or pull requests

2 participants