/**
* The required files
*/
require_once(HTML_BASE_UTIL_PATH.'/Element.php');
require_once(HTML_BASE_UTIL_PATH.'/Tabindex.php');
require_once(HTML_FORM_COMPONENT_PATH.'/Options.php');
require_once(HTML_FORM_COMPONENT_PATH.'/Option.php');
/**
* Generates a SELECT form element
* <code>
* Usage:
* $text = 'option text';
* $value = 'option value';
* // An array of option elements
* $options = array(
* array('text'=>'option 1','value'=>'1','selected'=>'','title'=>'','label'=>''),
* array('text'=>'option 2','value'=>'2','selected'=>'selected','title'=>'','label'=>''),
* array('text'=>'option 3','value'=>'3','selected'=>'','title'=>'','label'=>''),
* );
* $select = new Select($name,$class,$onchange,$multiple,$size,$disabled,'',$title,$tabindex);
* $select->add(new Option($value,$value)); // One or more single option elements
* : :
* print $select->getHtml();
* OR
* $select = new Select($name,$class,$onchange,$multiple,$size,$disabled,$options,$title,$tabindex);
* print $select->getHtml();
* OR
* $select = new Select($name,$class,$onchange,$multiple,$size,$disabled,'',$title,$tabindex);
* $select->add(new Options('$options,$name)); // An array of option elements
* print $select->getHtml();
* OR
* Select::start($name,$class,$onchange,$multiple,$size,$disabled,'',$title,$tabindex);
* Option::display($value,$value); // One or more single option elements
* : :
* Select::end();
* OR
* Select::start($name,$class,$onchange,$multiple,$size,$disabled,'',$title,$tabindex);
* Options::display($options,$name); // An array of option elements
* : :
* Select::end();
* OR
* Select::display($name,$class,$onchange,$multiple,$size,$disabled,$options,$title,$tabindex);
* </code>
* @package form
*/
class Select extends Element {
/**
* @var String $onchange The On change event
*/
var $onchange = '';
/**
* @var String $multiple The multiple select attribute
*/
var $multiple = '';
/**
* @var String $size The size
*/
var $size = '';
/**
* @var String $disabled The disabled (>IE4.x)
*/
var $disabled = '';
/**
* @var Options $options The new options object
*/
var $options = '';
/**
* Constructor
* @param String $name The name of the control
* @param String $class The class name
* @param String $onchange On Change Event name i.e. 'EMNE'
* @param String $multiple The multiple attribute
* @param String $size The size attribute
* @param String $disabled The disabled
* @param String $options The new options object, if present
* @param String $title The tooltip
* @param String $tabindex The tabindex
* @param String $accesskey The accesskey
*/
function Select($name,$class='',$onchange='',$multiple='',$size='',$disabled='',$options='',$title='',$tabindex='') {
$aClass = $class!=''?$class:CSS_SELECT_CLASS;
$value = ''; // Not for a Select
$accesskey = ''; // Not for a Select
$aTabindex = $tabindex!=''?$tabindex:Tabindex::next();
$onclick = ''; // Not used
$this->Element($name,$value,$aClass,$title,$aTabindex,$onclick,$accesskey);
$this->multiple = $multiple;
$this->size = $size;
$this->disabled = $disabled;
$this->options = $options;
if ($onchange!='') {
// TODO : Is it realy this functionality I want ?
$this->onchange = 'this.form['.$onchange.'].value=this.options[this.options.selectedIndex].value;';
}
}
/**
* Returns the html for the start of the control
* @return String the html
*/
function getStart() {
$html = '';
$html .= '<select';
$html .= $this->getAttribute('name');
$html .= $this->getAttribute('id');
$html .= $this->getAttribute('class');
$html .= $this->getAttribute('onchange');
$html .= $this->getAttribute('multiple');
$html .= $this->getAttribute('size');
$html .= $this->getAttribute('disabled');
$html .= $this->getAttribute('title');
$html .= $this->getAttribute('tabindex');
$html .= ">\r\n";
$html .= $this->getElements(); // as html
if ($this->options != '' && is_a($this->options, CLASS_NAME_OPTIONS)) {
$html .= $this->options->getHtml();
}
return $html;
}
/**
* Returns the html for the end of the control
* including the html for the added elements
* <code>
* Usage:
* $select = new Select('');
* print $select->getEnd();
* </code>
* @return String the complete html
*/
function getEnd() {
return "</select><br />\r\n";
}
/**
* Returns the html for the control
* including the html for the added elements
* @return String the complete html
*/
function getHtml() {
$html = $this->html;
$html .= $this->getStart();
$html .= $this->getEnd();
return $html;
}
/**
* Display start html
* <code>
* Usage:
* Select::start($name,$class,$onchange,$multiple,$size,$disabled,$onclick,$title,$tabindex);
* </code>
* @static
* @param String $name The name of the control
* @param String $class The class name
* @param String $onchange On Change Event name i.e. 'EMNE'
* @param String $multiple The multiple attribute
* @param String $size The size attribute
* @param String $disabled The disabled
* @param String $onclick On Click Event name i.e. 'EMNE'
* @param String $title The tooltip
* @param String $tabindex The tabindex
*/
function start($name,$class='',$onchange='',$multiple='',$size='',$disabled='',$onclick='',$title='',$tabindex='') {
$html = new Select($name,$class,$onchange,$multiple,$size,$disabled,$onclick,$title,$tabindex);
$html->addHtml($html->getStart());
}
/**
* Display end html
* <code>
* Usage:
* Select::end();
* </code>
* @static
*/
function end() {
$html = new Html();
$html->addHtml(Select::getEnd());
}
/**
* Display html
* <code>
* Usage:
* Select::display($name,$class,$onchange,$multiple,$size,$disabled,$options,$title,$tabindex,$accesskey);
* </code>
* @static
* @param String $name The name of the control
* @param String $class The class name
* @param String $onchange On Change Event name i.e. 'EMNE'
* @param String $multiple The multiple attribute
* @param String $size The size attribute
* @param String $disabled The disabled
* @param String $options The new options object
* @param String $title The tooltip
* @param String $tabindex The tabindex
*/
function display($name,$class='',$onchange='',$multiple='',$size='',$disabled='',$options='',$title='',$tabindex='') {
$html = new Select($name,$class,$onchange,$multiple,$size,$disabled,$options,$title,$tabindex);
$html->addHtml();
}
}
?>