开发者

JQuery UI Autocomplete, value after select (by mouse) is different than (by arrow-keys)

开发者 https://www.devze.com 2023-01-03 22:06 出处:网络
I\'m using jQuery UI Autocomplete 1.8.1 with Jquery 1.4.2 and I have this issue. At first, I can\'t force the value of the Autocomplete input field, well this is not a big problem.

I'm using jQuery UI Autocomplete 1.8.1 with Jquery 1.4.2 and I have this issue.

At first, I can't force the value of the Autocomplete input field, well this is not a big problem.

But I have this issue with it:

I doesn't act similarly when a user select a choice using mouse to using keyboard arrows. When using keyboard everything is fine and the value appears after select in the input text box, but when using mouse i开发者_运维问答t sticks with the old (typed) value not the selected one.

How to control this (textbox value after select)? and why there are different behaviours?

P.S: changing the value of the input box inside the select function is useless since it can't be done!


or you can add it in select

select: function( event, ui ) {
    $('#input').val(ui.item.value);
}


I had a similar problem to this.

When using the keyboard the focus from the text box is lost, but on click the focus goes back to the text box.

It could be that you have something happening on the focus of the input field which is being re-triggered?


You can do something like this:

$('#input').autocomplete({
   source: items,
   focus: function(event, ui) { var text = ui.item.value; 
   $('#input').val(text); 
   return false; 
   }
});

Hovering the item with the mouse, will fill the textbox with the current value, and when you click into it the value will be already displayed on the textbox


The sollution was to stop event by preventDefault() inside of autocomplete focus callback


I couldn't solve it in the prefect way, So I've managed to hide the search input field on select and display another customized div that is hidden on click the focus passed to the jQuery UI search input filed again.

0

精彩评论

暂无评论...
验证码 换一张
取 消