Change display field on multiple select


can you please tell me how to change display field on multi select box.
I have name and text columns in database and cms is using name column for display.
I would like to use text column.


  • edited 1:56AM
    The multi-select field has an options parameter to determine the options. By default it uses the model's "options_list" method which will usually use the first column (id) and the next column that doesn't have an "_id". This can be changed though by specifying different model params like so:
    $fields['my_select'] = array('type' => 'select', 'model' => 'my_model', 'model_params' => array('id', 'text'));
  • edited 1:56AM
    Hi, can you please specify how to get this option:

    This is my form_fields method, articles should have many comments.

    function form_fields($values=array(), $related=array())
    $fields = parent::form_fields($values, $related);

    $CI =& get_instance();

    $comments_options = $CI->Comments_model->options_list('id', 'text');
    foreach($article->comments as $comment)
    $comments_values[$comment->id] = $comment->name;
    $document_values = array();

    $comments_values = array_keys($comments_values);

    $fields['comments'] = array('type' => 'array', 'model' => 'comments_model', 'model_params' => array('id', 'text'), 'mode'=>'multi', 'value' => $comments_values, 'class' => 'add_edit comments');

    return $fields;

    This is working for now but I would like to know is there a simpler way to get selected values from database than writing all this code above $fields['comments'].

  • edited 1:56AM
    This is my has_many property: public $has_many = array('comments' => 'comments_model', 'tags' => array(FUEL_FOLDER => 'fuel_tags_model'));

    In else block is not: $document_values, it is: $comments_values.
  • edited 1:56AM
    If this is using a $has_many property, perhaps to simplify this matter and you always want to use "text" instead of "name" for your option display, you can overwrite the method on your comments_model:
    public function options_list($key = NULL, $val = NULL, $where = array(), $order = TRUE) { return parent::options_list('id', 'text', $where, $order); }
Sign In or Register to comment.