I recently noticed that the combobox item on an jQuery UI autocomplete grows way beyond the textfield input which is kinda ugly.
This is how i fix it (that is, make it as width as the input item):
$.extend($.ui.autocomplete.prototype.options, { open: function(event, ui) { $(this).autocomplete("widget").css({ "width": ($(this).width() + "px") }); } }); |
This code applies it to every autocomplete.
16 comments
Beautiful. Thanks a million, Michael. How I hated that ul stretch beyond the page limits…
Thanks Richard for your kind feedback, highly appreciated.
Thanks so much! I had copied the demo code exactly and was surprised to see the drop down menu extend all the way across the page.
Where did you put this code though? Thanks!
I put in the global scope before doing anything with JQuery. But i guess $(document).ready should work, also.
It saved my time. Many thanks!
Thanks!
Thanks, you are a life saver.
Thanks, excellent solution. I used “$(this).outerWidth()” in place of “$(this).width()” to get the width plus padding.
Thank you so much!!! Your solution with the combination of garudacrafts ‘s comment saved me !
Thank you, very helpful!
You’re welcome!
Hi Michael,
That’s great and solved my problem…almost…the autocomplete gets resized but the text now won’t wrap. Any advice?
Cheers.
Thank you, worked like a charm
Thanks a lot.
Thanks for this wonderful solution 🙂
One Trackback/Pingback
[…] 感谢Michael Simons https://info.michael-simons.eu/2013/05/02/how-to-fix-jquery-uis-autocomplete-width/ […]
Post a Comment