Change display field on multiple select

Hello,

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.

Comments

  • edited 12:37PM
    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'));
    http://docs.getfuelcms.com/general/forms#select
  • edited 12:37PM
    Hi, can you please specify how to get this option: http://docs.getfuelcms.com/general/forms#multi

    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();
    $CI->load->model('Comments_model');
    $CI->load->model('Articles_model');


    $comments_options = $CI->Comments_model->options_list('id', 'text');
    if(!empty($values['id']))
    {
    $article=$CI->Articles_model->find_one(array('id'=>$values['id']));
    foreach($article->comments as $comment)
    {
    $comments_values[$comment->id] = $comment->name;
    }
    }
    else
    {
    $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'].

    Tnx.
  • edited 12:37PM
    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 12:37PM
    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.