Jeff-Lewis / smarty-php

Automatically exported from code.google.com/p/smarty-php
0 stars 0 forks source link

html_options and classes #196

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When {html_options} is specified with a name param, it creates a select tag 
surrounding the provided options. When it does that, it applies any provided 
class not only to the select tag itself, but also to all the options within it. 
For example:

{html_options name="options" options=array("1" => "a", "2"=> "b", "3" => "c") 
class="form-control"}

What is the expected output?

<select class="form_control" name="options">
<option value="1">a</a>
<option value="2">b</a>
<option value="3">c</a>
</select>

What do you see instead?

<select class="form_control" name="options">
<option class="form_control" value="1">a</a>
<option class="form_control" value="2">b</a>
<option class="form_control" value="3">c</a>
</select>

I know that class is treated blindly (it's just another key-value pair) in this 
case, but it means that html_options can't be used for some things, for example 
bootstrap's select tags expect the class on the select, but falls to bits if it 
is also applied to the options. I think a reasonable approach would be to treat 
the class param specially and apply it to the options if the name is not 
provided (i.e. and no select tag is generated), but only apply it to the select 
if the name is provided.

Original issue reported on code.google.com by marcus.b...@gmail.com on 10 Jul 2014 at 4:17

GoogleCodeExporter commented 9 years ago
Hi 

Try something below

<select name="role" class="form_control">
{html_options options=options=array("1" => "a", "2"=> "b")}                    
</select>

Original comment by helloman...@gmail.com on 16 Jul 2015 at 2:21