JHtmlSelect

Utility class for creating HTML select lists

abstract
since

1.5

package

Joomla.Libraries

Methods

booleanlist

Generates a yes/no radio list.

booleanlist(string $name, array $attribs = array(), string $selected = null, string $yes = 'JYES', string $no = 'JNO', mixed $id = false) : string
static
since

1.5

see \JFormFieldRadio

Arguments

$name

stringThe value of the HTML name attribute

$attribs

arrayAdditional HTML attributes for the <select> tag

$selected

stringThe key that is selected

$yes

stringLanguage key for Yes

$no

stringLanguage key for no

$id

mixedThe id for the field or false for no id

Response

stringHTML for the radio list

genericlist

Generates an HTML selection list.

genericlist(array $data, string $name, mixed $attribs = null, string $optKey = 'value', string $optText = 'text', mixed $selected = null, mixed $idtag = false, boolean $translate = false) : string
static
since

1.5

Arguments

$data

arrayAn array of objects, arrays, or scalars.

$name

stringThe value of the HTML name attribute.

$attribs

mixedAdditional HTML attributes for the <select> tag. This can be an array of attributes, or an array of options. Treated as options if it is the last argument passed. Valid options are: Format options, see {@see JHtml::$formatOptions}. Selection options, see {@see JHtmlSelect::options()}. list.attr, string|array: Additional attributes for the select element. id, string: Value to use as the select element id attribute. Defaults to the same as the name. list.select, string|array: Identifies one or more option elements to be selected, based on the option key values.

$optKey

stringThe name of the object variable for the option value. If set to null, the index of the value array is used.

$optText

stringThe name of the object variable for the option text.

$selected

mixedThe key that is selected (accepts an array or a string).

$idtag

mixedValue of the field id or null by default

$translate

booleanTrue to translate

Response

stringHTML for the select list.

groupedlist

Generates a grouped HTML selection list from nested arrays.

groupedlist(array $data, string $name, array $options = array()) : string
static
since

1.5

throws

\RuntimeExceptionIf a group has contents that cannot be processed.

Arguments

$data

arrayAn array of groups, each of which is an array of options.

$name

stringThe value of the HTML name attribute

$options

arrayOptions, an array of key/value pairs. Valid options are: Format options, {@see JHtml::$formatOptions}. Selection options. See {@see JHtmlSelect::options()}. group.id: The property in each group to use as the group id attribute. Defaults to none. group.label: The property in each group to use as the group label. Defaults to "text". If set to null, the data array index key is used. group.items: The property in each group to use as the array of items in the group. Defaults to "items". If set to null, group.id and group. label are forced to null and the data element is assumed to be a list of selections. id: Value to use as the select element id attribute. Defaults to the same as the name. list.attr: Attributes for the select element. Can be a string or an array of key/value pairs. Defaults to none. list.select: either the value of one selected option or an array of selected options. Default: none. list.translate: Boolean. If set, text and labels are translated via JText::_().

Response

stringHTML for the select list

integerlist

Generates a selection list of integers.

integerlist(integer $start, integer $end, integer $inc, string $name, mixed $attribs = null, mixed $selected = null, string $format = '') : string
static
since

1.5

Arguments

$start

integerThe start integer

$end

integerThe end integer

$inc

integerThe increment

$name

stringThe value of the HTML name attribute

$attribs

mixedAdditional HTML attributes for the <select> tag, an array of attributes, or an array of options. Treated as options if it is the last argument passed.

$selected

mixedThe key that is selected

$format

stringThe printf format to be applied to the number

Response

stringHTML for the select list

optgroup

Create a placeholder for an option group.

optgroup(string $text, string $optKey = 'value', string $optText = 'text') : \stdClass
static deprecated
deprecated

4.0 Use JHtmlSelect::groupedList()

see \JHtmlSelect::groupedList()
since

1.5

Arguments

$text

stringThe text for the option

$optKey

stringThe returned object property name for the value

$optText

stringThe returned object property name for the text

Response

\stdClass

option

Create an object that represents an option in an option list.

option(string $value, string $text = '', mixed $optKey = 'value', string $optText = 'text', boolean $disable = false) : \stdClass
static
since

1.5

Arguments

$value

stringThe value of the option

$text

stringThe text for the option

$optKey

mixedIf a string, the returned object property name for the value. If an array, options. Valid options are: attr: String|array. Additional attributes for this option. Defaults to none. disable: Boolean. If set, this option is disabled. label: String. The value for the option label. option.attr: The property in each option array to use for additional selection attributes. Defaults to none. option.disable: The property that will hold the disabled state. Defaults to "disable". option.key: The property that will hold the selection value. Defaults to "value". option.label: The property in each option array to use as the selection label attribute. If a "label" option is provided, defaults to "label", if no label is given, defaults to null (none). option.text: The property that will hold the the displayed text. Defaults to "text". If set to null, the option array is assumed to be a list of displayable scalars.

$optText

stringThe property that will hold the the displayed text. This parameter is ignored if an options array is passed.

$disable

booleanNot used.

Response

\stdClass

options

Generates the option tags for an HTML select list (with no select tag surrounding the options).

options(array $arr, mixed $optKey = 'value', string $optText = 'text', mixed $selected = null, boolean $translate = false) : string
static
since

1.5

Arguments

$arr

arrayAn array of objects, arrays, or values.

$optKey

mixedIf a string, this is the name of the object variable for the option value. If null, the index of the array of objects is used. If an array, this is a set of options, as key/value pairs. Valid options are: -Format options, {@see JHtml::$formatOptions}. -groups: Boolean. If set, looks for keys with the value "<optgroup>" and synthesizes groups from them. Deprecated. Defaults true for backwards compatibility. -list.select: either the value of one selected option or an array of selected options. Default: none. -list.translate: Boolean. If set, text and labels are translated via JText::_(). Default is false. -option.id: The property in each option array to use as the selection id attribute. Defaults to none. -option.key: The property in each option array to use as the selection value. Defaults to "value". If set to null, the index of the option array is used. -option.label: The property in each option array to use as the selection label attribute. Defaults to null (none). -option.text: The property in each option array to use as the displayed text. Defaults to "text". If set to null, the option array is assumed to be a list of displayable scalars. -option.attr: The property in each option array to use for additional selection attributes. Defaults to none. -option.disable: The property that will hold the disabled state. Defaults to "disable". -option.key: The property that will hold the selection value. Defaults to "value". -option.text: The property that will hold the the displayed text. Defaults to "text". If set to null, the option array is assumed to be a list of displayable scalars.

$optText

stringThe name of the object variable for the option text.

$selected

mixedThe key that is selected (accepts an array or a string)

$translate

booleanTranslate the option values.

Response

stringHTML for the select list

radiolist

Generates an HTML radio list.

radiolist(array $data, string $name, string $attribs = null, mixed $optKey = 'value', string $optText = 'text', string $selected = null, boolean $idtag = false, boolean $translate = false) : string
static
since

1.5

Arguments

$data

arrayAn array of objects

$name

stringThe value of the HTML name attribute

$attribs

stringAdditional HTML attributes for the <select> tag

$optKey

mixedThe key that is selected

$optText

stringThe name of the object variable for the option value

$selected

stringThe name of the object variable for the option text

$idtag

booleanValue of the field id or null by default

$translate

booleanTrue if options will be translated

Response

stringHTML for the select list

suggestionlist

Method to build a list with suggestions

suggestionlist(array $data, string $optKey = 'value', string $optText = 'text', mixed $idtag = null, boolean $translate = false) : string
static deprecated
since

3.2

deprecated

4.0 Just create the <datalist> directly instead

Arguments

$data

arrayAn array of objects, arrays, or values.

$optKey

stringThe name of the object variable for the option value. If set to null, the index of the value array is used.

$optText

stringThe name of the object variable for the option text.

$idtag

mixedValue of the field id or null by default

$translate

booleanTrue to translate

Response

stringHTML for the select list

Properties

optionDefaults

Default values for options. Organized by option group.

static
since

1.5

Type(s)

array