I have jQuery chosen named centro medicos in an insertion form, I can select all data, select some of the data. If I click select all here is the result:
Let's say that I select only 3 items and then I save. Now I want to edit. When the edit page is loaded I want to have the 3 items that I selected loaded:
And if I click on select all (Selectionar todo) the rest of items are displayed.
1- Controller
public function edit_form()
{
$edit_id= $this->uri->segment(3);
$data['ITEM_EDIT'] = $this->model->get_title_by_id($edit_id);
$data['ITEM_ALL']= $this->model->get_all_title();
$this->load->view('view_edit_form', $data);
}
2- View
<select class="chosen-select" multiple name="item[]">
<?php
foreach($ITEM_ALL as $item_all) {
foreach($ITEM_EDIT as $item_edit) {
if($title_edit->title== $title_all->title)
{
echo '<option value="'.$item_all->title.'" class="'.$item_all->id.'" selected>'.$item_all->title.'</option>';
}
else
{
echo '<option value="'.$item_all->title.'" class="'.$item_all->id.'" >'.$item_all->title.'</option>';
}
}
}
?>
</select>
3- jQuery
$(".chosen-select").chosen({
no_results_text: "Oops, nothing found : ",
})
How can I achieve this?