34 public function __construct( $name =
false, $id =
false, $default =
false ) {
67 $this->attributes[$name] = $value;
75 return $this->attributes[$name] ??
null;
82 public function addOption( $label, $value =
false ) {
83 $value = $value !==
false ? $value : $label;
84 $this->options[] = [ $label => $value ];
110 foreach (
$options as $label => $value ) {
111 if ( is_array( $value ) ) {
112 $contents = self::formatOptions( $value,
$default );
113 $data .= Html::rawElement(
'optgroup', [
'label' => $label ], $contents ) .
"\n";
119 $data .= Xml::option( $label, $value, $selected ) .
"\n";
132 foreach ( $this->options as
$options ) {
133 $contents .= self::formatOptions( $options, $this->
default );
136 return Html::rawElement( $this->tagName, $this->attributes, rtrim( $contents ) );
150 foreach ( explode(
',', $msg ) as $option ) {
152 if ( strpos( $option,
':' ) ===
false ) {
153 $option =
"$option:$option";
156 [ $label, $value ] = explode(
':', $option );
157 $options[ trim( $label ) ] = trim( $value );
Class for generating HTML <select> or <datalist> elements.
static parseOptionsMessage(string $msg)
Parse labels and values out of a comma- and colon-separated list of options, such as is used for expi...
setAttribute( $name, $value)
__construct( $name=false, $id=false, $default=false)
static formatOptions( $options, $default=false)
This accepts an array of form: label => value label => ( label => value, label => value )
addOption( $label, $value=false)
addOptions( $options)
This accepts an array of form label => value label => ( label => value, label => value )