-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
Fix input.value undefined
#770
base: master
Are you sure you want to change the base?
Conversation
@cavasinf can you share a reproduction for the original issue you found? I'm struggling to see how |
I'm seeing the same issue. I'm trying to integrate tom-select into Request Tracker, so it's hard to create a minimal test case. You can see it in this branch, but you need to set up an environment to run RT, which is some work: https://github.com/bestpractical/rt/tree/6.0/add-tom-select Inspecting the element generating the error, it looks like an input created by tom-select rather than RT itself.
It looks like a Status dropdown for a ticket, but the input doesn't look like what RT would generate. Anything else I can provide to help debug? |
If I had to hazard a guess, I'd say that for some reason this function is returning something unexpected: Lines 10 to 27 in 78c0d46
The value returned from there is ultimately passed to Line 117 in 78c0d46
Which in turn is used in the Lines 145 to 173 in 78c0d46
Consider adding a breakpoint, logpoint, or just a |
Hey, sorry for the late reply! I honestly don’t remember exactly what scenario led us to encounter that issue. That said, if we expect both |
I updated my comment above to correctly display the element, it was hidden before. Looking at that I agree with @cavasinf , looking at the code, the |
Looking at the code before the JS vanilla refactoring: The |
All My worry is that adding optional chaining here will just mask a deeper problem: either with your own code, or perhaps an invariant that I'd like to have a reproduction of this bug, ideally one that could be turned into a failing test case, before accepting a change. |
Working with this some more, I have an idea what is going on. I was using the code suggested in the docs to find all select elements on the page with a class:
On a dashboard in RT, the main page loads, then individual components load via AJAX. To cover all select elements, I was running an "initialize" function multiple times as components were loaded. I used this to avoid calling new on elements that had already been processed.
As components are loading via AJAX, I think TomSelect was adding the dynamic input box. Even though my class wasn't directly on the ts-generated input tag, it looks like the TomSelect code added my classes to a surrounding div, along with "ts-wrapper". So I think that div was getting returned by querySelectorAll. And maybe that div is the element that doesn't have a value because it's not an input. To test this, I tightened my selector to target only So I think users may see this error with applications running some AJAX that loads more markup dynamically, then they try to initialize again and end up grabbing some ts-generated elements that included the class name they used. Does the above seem possible? |
That definitely sounds plausible, yeah. Weird things will happen if you have a selector that targets any DOM elements created by I'm inclined to say it's outside the scope of this project to check for and handle things like this. What do you think? If this PR were merged, it would just mask the fact that you're sort of recursively creating |
Yeah, now that I see what is going on, I'm inclined to agree. The error is pointing out an unexpected use case. It would help with debugging to check the input for expected types and bail with a message, but that's a different PR. I think a doc update would be easier and help new users. If I wanted to take a shot at providing some info on the two issues I encountered and possible fixes, where would that go? Maybe a new section at the bottom of the Usage page? |
Fix error when using
trim()
on an undefined value.I don't know if you guys accept optional chaining for browser compatibility.
eg:
So I've ended up using a simple ternary operator.