Reputation: 2853
I have taken a list of items from a table in my DB , now I want to make a form that consists of a dropdown box containing all these items. And when I click an item I want it to be added to a list next to the listbox so I can save these multiple items in my db . (The main goal is to select a single or multiple labels for a newsitem in my site)
code in html that gives list of labels (working) :
@foreach($labels as $label)
<p>{{$label}}</p>
@endforeach
Now I need a {{Form:: ...... element that creates a dropdown box of all these labels.
Upvotes: 0
Views: 744
Reputation: 2853
I solved this with a jquery plugin :
http://harvesthq.github.io/chosen/
and this code :
<div class="form-group">
<select name="labels[]" class="form-control chosen-select-video" data-placeholder="Add labels..." multiple >
@foreach ($labels as $title)
<option value="{{$title}}">{{ucfirst($title)}}</option> <!-- Capitalize first letter -->
@endforeach
</select>
</div>
Upvotes: 1
Reputation: 1215
To create a dropdown list in laravel you can use-
echo Form::select('size', array('L' => 'Large', 'S' => 'Small'));
here array
is your list taken from database. you can find details about laravel form helper in this link. and for showing a list of selected item next to your dropdownlist you should use javascript or jQuery.
Upvotes: 0