From the example of $crud->set_relation_n_n that can be found in the GC site we could easily create a multiselect field. I have tried it and it works perfectly. However, one time it came into my requirement that I need to add data on runtime into the list (i.e. in category). I wonder if it is possible to add a new option into the select field.
function film_management() { $crud = new grocery_CRUD(); $crud->set_table('film'); $crud->set_relation_n_n('actors', 'film_actor', 'actor', 'film_id', 'actor_id', 'fullname','priority'); $crud->set_relation_n_n('category', 'film_category', 'category', 'film_id', 'category_id', 'name'); $crud->unset_columns('description','special_features','last_update'); $crud->fields('title', 'description', 'actors' , 'category' ,'release_year', 'rental_duration', 'rental_rate', 'length', 'replacement_cost', 'rating', 'special_features'); $output = $crud->render(); $this->_example_output($output); }
What I have tried so far is using javascript like this below. However, though it shown on display but functionally it didn't work out. Clicking on the new option will not display its data in the multiselect field.
$("#field-Category").append('<option value=1>My option</option>'); $(".chzn-results").append('<li id="field_INTERESTED_chzn_o_11" class="active-result" style="">My option</li>');
Does anybody have tried so far or have this kind of implementation before? Appreciate if someone could provide me some solution or could say that this is not possible. : )
Thanks,