An example with select2. I think it's a powerful library!!! download select2.js and just add the styles and js files.
@section('styles')
{{ HTML::style('css/select2.css')}}
{{ HTML::style('css/select2-bootstrap.css')}}
@stop
.....
<div class="col-md-7">
{{Form::text('city_id',0,['class'=>'form-control input-sm','required'=>'','id'=>'city_id'])}}
<span class="help-block text-center">cities</span>
</div>
.....
@section('scripts')
{{ HTML::script('js/select2.min.js')}}
{{ HTML::script('app-js/citySearch.js'); }}
<script type="text/javascript">
//init with the values you saved (if it's the case that you are asking for)
citySeach(true);
$("#city_id").select2('data', [
@foreach ($cities as $city)
{id:{{ $city->id }},text:"{{ $city->name.' '.$city->postCode }}"},
@endforeach
]);
</script>
@stop
Maybe, and if its the case, when you save, and if it's multiple you can do in the controller $cities = Input::get('city_id',''); $city_id_array = explode(',',$cities); ->sync($city_id_array') or if it just one value fiels city_id or for other thing just directly use $city
citySearch.js
function citySeach(multi)
{
$('#city_id').select2({
placeholder: "search city",
minimumInputLength: 3,
allowClear: true,
multiple: multi,
ajax: {
url: BASE+'/city/search',
dataType: 'json',
quietMillis: 100,
data: function (term) {
return {
term: term
};
},
results: function (data) {
var myResults = [];
$.each(data, function (index, item) {
myResults.push({
id: item.id,
text: item.name+' '+item.postCode
});
});
return {
results: myResults
};
}
}
});
}
this is only a snippet, idea, of a case where I use select2 ...
if you need to return to that input you should do something like this!