⚠ In case you've missed it we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This forum is read-only and soon will be archived. ⚠

How 're-create' the multiselect field style with callback_edit_field

callback callback_edit_field multiselect custom_query style

  • Please log in to reply
1 reply to this topic

#1 marlaaragao


    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 27 July 2015 - 08:10 PM



This probably is a dumb question, but I'm struggling with it for the past 2 days. I have a field that is of type multiselect, so, when i'm in the add action, I just get the information from a relation table and add it to the field, as told in the documentation for multiselect.


However, when I'm in edit action, I need the field to come with the data that was selected before, so I have the callback_edit_field to generate the select field and it's options and the selected ones.


My problem is: my field comes as a simple select field, as in the image below. I used the 'chosen-multiple-select chzn-done' css class but it's not applied (I know that it would not be that simple.). Can anyone help me show this field as the default grocery crud multiselect field? Thank you!


PS.: As I use custom model and a custom query, I could'nt make the relation_n_n work, so that's why I'm using callback to edit field. Thanks!




My code for the callback_edit_field:

function _callback_edit_aplicacoes($value, $primary_key) {
        $result = '<select id="aplicacoes" multiple="multiple" name="aplicacoes[]" '
                . ' class="chosen-multiple-select chzn-done">';

        $aplicacoes = $this->aplicacao->findAll();
        $aplicacoesAdmin = $this->aplicacao->findAllAdmin($primary_key);

        if (is_array($aplicacoes) && is_array($aplicacoesAdmin)) {
            foreach ($aplicacoes as $a) {

                $result .= '<option value="' . $a->id . '" '
                        . (in_array($a, $aplicacoesAdmin) ? ' selected="selected" ' : '') . ' >' . $a->name . '</option>';
        $result .= '</select>';
        return $result;

Thank you!

#2 tomomiha



  • Members
  • Pip
  • 4 posts

Posted 23 December 2015 - 11:07 AM

If I understand correctly, try this:

on insert, try to save multiselect options in comma-separated form eg.: 1,2,3,  to database column

and then it will be automatically displayed in edit form, without any need for callbacks.

Also tagged with one or more of these keywords: callback, callback_edit_field, multiselect, custom_query, style

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users