[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/inc/Form/ -> DropdownElement.php (summary)

(no description)

File Size: 198 lines (6 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

DropdownElement:: (9 methods):
  __construct()
  addOptGroup()
  optGroups()
  options()
  attr()
  val()
  getFirstOption()
  setValueInOptGroups()
  mainElementHTML()


Class: DropdownElement  - X-Ref

Class DropdownElement

Represents a HTML select. Please note that this does not support multiple selected options!

__construct($name, $options, $label = '')   X-Ref

param: string $name The name of this form element
param: array  $options The available options
param: string $label The label text for this element (will be autoescaped)

addOptGroup($label, $options)   X-Ref
Add an `<optgroup>` and respective options

param: string $label
param: array  $options
return: OptGroup a reference to the added optgroup

optGroups($optGroups = null)   X-Ref
Set or get the optgroups of an Dropdown-Element.

optgroups have to be given as associative array
* the key being the label of the group
* the value being an array of options as defined in @see OptGroup::options()

param: null|array $optGroups
return: OptGroup[]|DropdownElement

options($options = null)   X-Ref
Get or set the options of the Dropdown

Options can be given as associative array (value => label) or as an
indexd array (label = value) or as an array of arrays. In the latter
case an element has to look as follows:
option-value => array (
'label' => option-label,
'attrs' => array (
attr-key => attr-value, ...
)
)

param: null|array $options
return: $this|array

attr($name, $value = null)   X-Ref
Gets or sets an attribute

When no $value is given, the current content of the attribute is returned.
An empty string is returned for unset attributes.

When a $value is given, the content is set to that value and the Element
itself is returned for easy chaining

param: string $name Name of the attribute to access
param: null|string $value New value to set
return: string|$this

val($value = null)   X-Ref
Get or set the current value

When setting a value that is not defined in the options, the value is ignored
and the first option's value is selected instead

param: null|string $value The value to set
return: $this|string

getFirstOption()   X-Ref
Returns the first options as it will be rendered in HTML

return: string

setValueInOptGroups($value)   X-Ref
Set the value in the OptGroups, including the optgroup for the options without optgroup.

param: string $value
return: bool

mainElementHTML()   X-Ref
Create the HTML for the select it self

return: string