TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Kohana Form::select()
  • Hey guys, I have a question. I need to get option

    option style="style" value="somevalue"

    in Kohana, how do I get that?

    I already defined next:

    Controller Something:

    $colors = ORM::factory('Color')
                $colors_array = array();
                foreach ($colors as $color)
                    $colors_array[$color->id] = $color->name;

    Model Something:

    'color'  => array();

    Model Color:

    'colors' => array();
  • $colors = ORM::factory('Color')
                $colors_array = array();
                foreach ($colors as $color)
                    $colors_array[$color->id] = $color->name;


    $colors = ORM::factory('Color')->find_all()->as_array('id', 'name');
  • I forgot to mention, I have 3 fields in DB: id: 1 name: Somename hex: 00000

    Hex should represent option style="hex" and "value" should be name

  • $colors = ORM::factory('Color')->find_all()->as_array('hex', 'name');
  • By the way, the only attributes that Form::select() lets you have on an option element are value and selected. You can't set style.

  • @samwilson Form::select('color', $color, $colors, array('id' => 'field-type', 'style' => 'color:'.$hex));

  • @artad Each options should have different color. That's just for "select" form whole :)

  • @Naden @artad, that's what I was getting at. :-) You can set attributes on the select element, but not on the options inside it.

  • That's bad, should be added someday.

    Thanks anyways guys :)

  • @samwilson you are right.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion