I'm trying to implement an autocomplete box into a search bar. When I being to type in the text, the box expands to fill my entire screen. Is there any way I can decrease the size of the box that pops up? I'm sort of new to jQuery, so I'm hoping it is just some option I can set. Code is like this.
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var data = {% autoescape false %}{{job_names}}{% endautoescape %};
$("#job_names").autocomplete({source : data});
});
</script>
<form name= "search_form" method= "post" action= "/" onSubmit="return validate(this);">
<input id="job_names" type= "text"/>
<input type= "submit" value= "Search" id= "search"/>
</form>
A thing to note, job_names is a list passed in through my flask/python backend.
Add the following CSS to your html page, it will apply an overflow setting and set the width of the auto complete list:
/**causes the autocomplete to align left and overflow with vertical scroll bar **/
ul
{
text-align:left;
width: 150px;
}
.ui-autocomplete
{
max-height: 200px;
overflow-y: auto;
overflow-x: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
http://jsfiddle.net/sanpopo/4J9tK/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With