Difference between revisions of "JHtmlSelect/option"
From Joomla! Documentation
< API16:JHtmlSelect
(New page: ===Description===
Create an object that represents an option in an option list.
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JHtmlSelect/option|Ed...) |
m (removing red link to edit, no existant pages) |
||
Line 3: | Line 3: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Syntax=== | ===Syntax=== | ||
Line 100: | Line 100: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Examples=== | ===Examples=== | ||
Line 115: | Line 115: | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
+ | [[Category:Archived pages API16]] |
Revision as of 21:58, 13 May 2013
The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
Create an object that represents an option in an option list.
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax[edit]
static option($value, $text= '', $optKey= 'value', $optText= 'text', $disable=false)
Parameter Name | Default Value | Description |
---|---|---|
$value | The value of the option | |
$text | The text for the option | |
$optKey | 'value' | If a string, the returned object property name for the value. If an array, options. Valid options are: |
$optText | 'text' | The property that will hold the the displayed text. This parameter is ignored if an options array is passed. |
$disable | false |
Returns[edit]
object
Defined in[edit]
libraries/joomla/html/html/select.php
Importing[edit]
jimport( 'joomla.html.html.select' );
Source Body[edit]
public static function option(
$value, $text = '', $optKey = 'value', $optText = 'text', $disable = false
) {
$options = array(
'attr' => null,
'disable' => false,
'option.attr' => null,
'option.disable' => 'disable',
'option.key' => 'value',
'option.label' => null,
'option.text' => 'text',
);
if (is_array($optKey)) {
// Merge in caller's options
$options = array_merge($options, $optKey);
} else {
// Get options from the parameters
$options['option.key'] = $optKey;
$options['option.text'] = $optText;
$options['disable'] = $disable;
}
$obj = new JObject;
$obj->$options['option.key'] = $value;
$obj->$options['option.text'] = trim($text) ? $text : $value;
/*
* If a label is provided, save it. If no label is provided and there is
* a label name, initialise to an empty string.
*/
$hasProperty = $options['option.label'] !== null;
if (isset($options['label'])) {
$labelProperty = $hasProperty ? $options['option.label'] : 'label';
$obj->$labelProperty = $options['label'];
} elseif ($hasProperty) {
$obj->$options['option.label'] = '';
}
// Set attributes only if there is a property and a value
if ($options['attr'] !== null) {
$obj->$options['option.attr'] = $options['attr'];
}
// Set disable only if it has a property and a value
if ($options['disable'] !== null) {
$obj->$options['option.disable'] = $options['disable'];
}
return $obj;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples[edit]
<CodeExamplesForm />