Basically, im having a hard time getting the correct value from a jquery UI input with a autocomplete at times. Iv created a jsfiddle to demonstrate the behavior. Hard to explain the exact issue, but here’s the fiddle:
To reproduce, follow these steps exactly, while having the browser dev tools js console open:
- focus on the text input
- move the mouse away from the input
- type c
- press arrow down on the keyboard to select “abc”
- hover over the option “cde”
- click the button.
error: I wont get any value. undefined is logged to the console.
expected: whatever value is inside the input box. please =)
If it matters, im using chrome.
If you swap the
changehandler by ablurone it will work as intended:I’m not sure why, but I assume the UI programmatically fires
changeevents which affect the outcome of your storedvaluevariable.Also, if you want to always get the current value of text input, you can query it when using it instead of storing it in a variable:
There may be some restriction on your project for you to not be using that yet, but it’s the most bulletproof method if you can use it.