Re: [SMARTY-DEV] html_options
| From: | Danilo Buerger | Date: | Mon, 26 Feb 2007 12:44:58 +0000 |
| Subject: | Re: [SMARTY-DEV] html_options | ||
| References: | 1 2 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-2969@lists.php.net to get a copy of this message | ||
messju mohr schrieb:
Hi, what about multiple selected values, then?Good point, but that raises another bug. When using multiple selected values, the <select> tag should have a multiple="multiple" attribute. Of course this could be applied by a feature where every attribute in the {html_options} that isnt one of values/output/selected/options/name is appended to the <select> tag (if present). So i guess the approach should be if name is specified and multiple select values exist multiple="multiple" should be automatically applied to the <select> tag (if present). Here is a patch for this, which also fixes the first issue but keeps the selected attribute as array: Index: plugins/function.html_options.php =================================================================== RCS file: /repository/smarty/libs/plugins/function.html_options.php,v retrieving revision 1.25 diff -r1.25 function.html_options.php 58c58
< $$_key = array_map('strval', array_values((array)$_val));
---
$$_key = array_values((array)$_val);90a91,93
if (count($selected) > 1) {
$extra = ' multiple="multiple"' . $extra;
}
The documentation of html_options contains a bug as well:
Example 8-15 assigns "lookups" and "fav" but the template uses "myOptions" and "mySelect". The template defines the name of the select as "foo" but the output has "breakTime" as selects name.
IMHO this is not a bug in html_options(), it's an incostistency in php's type system. php does not support boolean values as array keys, so don't use them as such.From http://de2.php.net/manual/en/language.types.array.php: "Using TRUE as a key will evaluate to integer 1 as key. Using FALSE as a key will evaluate to integer 0 as key." This clearly allows the use of boolean values as array keys.
On Sat, Feb 24, 2007 at 07:39:05PM +0100, Danilo Buerger wrote:Hey list, User Sweetums recently asked on the IRC channel about a weird problem in html_options. See this code snipet: --- template --- {html_options name=foo options=$myOptions selected=$mySelect} --- .php --- $smarty->assign('myOptions', array(true => 'test', false => 'foo')); $smarty->assign('mySelect', false); $smarty->display('test.tpl'); This will not select foo as default option because the boolean in select is casted to a string (resulting in an empty string) but in options the boolean is casted to an int (resulting in 0). This patch should fix it up: Index: plugins/function.html_options.php =================================================================== RCS file: /repository/smarty/libs/plugins/function.html_options.php,v retrieving revision 1.25 diff -r1.25 function.html_options.php 58c58< $$_key = array_map('strval', array_values((array)$_val));---102c102$$_key = $_val;< if (in_array((string)$key, $selected))----- Smarty Development Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpif ((string)$key == $selected)