Multiple dependency selection in php using select2 in CI

I am using select2 plugin to select.

I have several forms with an employee name and three multiple selection fields for the department of location and position in each form, where each employee has several locations and in each place can have several departments and position, which means that the department and position depend on the location with respect to each employee.

The department and position are shown in optgroup for the location where the department and position are displayed as an option.

Problem

I saved all the values ​​in my database. how to show all selected values ​​of location, department and position in relation to the employee when I am in the editing part.

enter image description here

+4
2

...

 ,

echo '<option value="$value"';
if(in_array($value,$array)) echo 'selected';
echo '>$name</option>';
+1

select2 , .

, . location1,location2..

.

var location_array= location_string.split(', ');                
$('#your_select2_id_of_location').val(location_array).trigger("change");

selct2 .

, .

+1

Source: https://habr.com/ru/post/1681500/


All Articles