Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
combo.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Form
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 JFormHelper::loadFieldClass('list');
13 
14 /**
15  * Form Field class for the Joomla Platform.
16  * Implements a combo box field.
17  *
18  * @package Joomla.Platform
19  * @subpackage Form
20  * @since 11.1
21  */
23 {
24  /**
25  * The form field type.
26  *
27  * @var string
28  * @since 11.1
29  */
30  protected $type = 'Combo';
31 
32  /**
33  * Method to get the field input markup for a combo box field.
34  *
35  * @return string The field input markup.
36  *
37  * @since 11.1
38  */
39  protected function getInput()
40  {
41  $html = array();
42  $attr = '';
43 
44  // Initialize some field attributes.
45  $attr .= !empty($this->class) ? ' class=combobox"' . $this->class . '"' : ' class="combobox"';
46  $attr .= $this->readonly ? ' readonly' : '';
47  $attr .= $this->disabled ? ' disabled' : '';
48  $attr .= !empty($this->size) ? ' size="' . $this->size . '"' : '';
49  $attr .= $this->required ? ' required aria-required="true"' : '';
50 
51  // Initialize JavaScript field attributes.
52  $attr .= $this->onchange ? ' onchange="' . $this->onchange . '"' : '';
53 
54  // Get the field options.
55  $options = $this->getOptions();
56 
57  // Load the combobox behavior.
58  JHtml::_('behavior.combobox');
59 
60  $html[] = '<div class="combobox input-append">';
61 
62  // Build the input for the combo box.
63  $html[] = '<input type="text" name="' . $this->name . '" id="' . $this->id . '" value="'
64  . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $attr . ' autocomplete="off" />';
65 
66  $html[] = '<div class="btn-group">';
67  $html[] = '<button type="button" class="btn dropdown-toggle">';
68  $html[] = ' <span class="caret"></span>';
69  $html[] = '</button>';
70 
71  // Build the list for the combo box.
72  $html[] = '<ul class="dropdown-menu">';
73 
74  foreach ($options as $option)
75  {
76  $html[] = '<li><a href="#">' . $option->text . '</a></li>';
77  }
78 
79  $html[] = '</ul>';
80 
81  $html[] = '</div></div>';
82 
83  return implode($html);
84  }
85 }