Son of Multiselect is a more usable, all browsers, gracefully failing custom control that kind of just stole my heart a little.
Embedding it in HTML_QuickForm is a piece of piss too.
require_once('HTML/QuickForm.php');
require_once('HTML/QuickForm/select.php');
$GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES']['mselect'] =
array('HTML/QuickForm/mselect.php','HTML_QuickForm_mselect');
class HTML_QuickForm_mselect extends HTML_QuickForm_select {
// {{{ toHtml()
/**
* Returns the SELECT in HTML
*
* @since 1.0
* @access public
* @return string
*/
function toHtml()
{
if (!defined('HTML_QUICKFORM_MSELECT_EXISTS')) {
$js = '<script type="text/javascript"
src=\'multiselect.js\'></script>' . "\n";
define('HTML_QUICKFORM_MSELECT_EXISTS', true);
} else {
$js = "";
}
return $js . parent::toHTML();
} //end func toHtml
// }}}
} //end class HTML_QuickForm_mselect
Using it?
public static function MultipleSelect( $name, $elements,
$params, $default = array()) {
ob_start();
require_once( 'HTML/QuickForm/mselect.php' );
$a = @HTML_Quickform::createElement( 'mselect', $name,
"", $elements, $params );
$a->setMultiple(true);
$a->setValue( $default );
print $a->toHtml();
return ob_get_clean();
}
Tada: Pretty, isn't it
print CLS_html::MultipleSelect2("control[]",
array("one", "two", "three"),
array("size" => 6), array(1));
No comments:
Post a Comment