10 defined(
'JPATH_PLATFORM') or die;
30 protected $type =
'Text';
65 public function __get($name)
75 return parent::__get($name);
88 public function __set($name, $value)
93 $this->maxLength = (int) $value;
97 $value = (string) $value;
98 $value = ($value == $name || $value ==
'true' || $value ==
'1');
101 $this->name = (string) $value;
105 parent::__set($name, $value);
123 public function setup(SimpleXMLElement $element, $value, $group = null)
125 $result = parent::setup($element, $value, $group);
129 $inputmode = (string) $this->element[
'inputmode'];
130 $dirname = (string) $this->element[
'dirname'];
132 $this->inputmode =
'';
133 $inputmode = preg_replace(
'/\s+/',
' ', trim($inputmode));
134 $inputmode = explode(
' ', $inputmode);
136 if (!empty($inputmode))
138 $defaultInputmode = in_array(
'default', $inputmode) ?
JText::_(
"JLIB_FORM_INPUTMODE") .
' ' :
'';
140 foreach (array_keys($inputmode,
'default') as $key)
142 unset($inputmode[$key]);
145 $this->inputmode = $defaultInputmode . implode(
" ", $inputmode);
149 $dirname = ((string) $dirname ==
'dirname' || $dirname ==
'true' || $dirname ==
'1');
150 $this->dirname = $dirname ? $this->getName($this->fieldname .
'_dir') :
false;
152 $this->maxLength = (int) $this->element[
'maxlength'];
165 protected function getInput()
168 $hint = $this->translateHint ?
JText::_($this->hint) : $this->hint;
171 $size = !empty($this->size) ?
' size="' . $this->size .
'"' :
'';
172 $maxLength = !empty($this->maxLength) ?
' maxlength="' . $this->maxLength .
'"' :
'';
173 $class = !empty($this->
class) ?
' class="' . $this->
class . '"' : '';
174 $readonly = $this->readonly ? ' readonly' : '';
175 $disabled = $this->disabled ? ' disabled' : '';
176 $required = $this->required ? ' required aria-required="true"' : '';
177 $hint = $hint ? ' placeholder="' . $hint . '"' : '';
178 $autocomplete = !$this->autocomplete ? ' autocomplete="off"' : ' autocomplete="' . $this->autocomplete . '"';
179 $autocomplete = $autocomplete == ' autocomplete="on"' ? '' : $autocomplete;
180 $autofocus = $this->autofocus ? ' autofocus' : '';
181 $spellcheck = $this->spellcheck ? '' : ' spellcheck="false"';
182 $pattern = !empty($this->pattern) ? ' pattern="' . $this->pattern . '"' : '';
183 $inputmode = !empty($this->inputmode) ? ' inputmode="' . $this->inputmode . '"' : '';
184 $dirname = !empty($this->dirname) ? ' dirname="' . $this->dirname . '"' : '';
188 $onchange = !empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : '';
191 JHtml::_('jquery.framework');
192 JHtml::_('script', 'system/html5fallback.js', false, true);
195 $options = (array) $this->getSuggestions();
197 if (!empty($options))
199 $html[] = JHtml::_(
'select.suggestionlist', $options,
'value',
'text', $this->
id .
'_datalist"');
200 $list =
' list="' . $this->
id .
'_datalist"';
203 $html[] =
'<input type="text" name="' . $this->name .
'" id="' . $this->
id .
'"' . $dirname .
' value="'
204 . htmlspecialchars($this->value, ENT_COMPAT,
'UTF-8') .
'"' . $class . $size . $disabled . $readonly . $list
205 . $hint . $onchange . $maxLength . $required . $autocomplete . $autofocus . $spellcheck . $inputmode . $pattern .
' />';
207 return implode($html);
217 protected function getSuggestions()
221 foreach ($this->element->children() as $option)
224 if ($option->getName() !=
'option')
230 $options[] = JHtml::_(
231 'select.option', (
string) $option[
'value'],
232 JText::alt(trim((
string) $option), preg_replace(
'/[^a-zA-Z0-9_\-]/',
'_', $this->fieldname)),
'value',
'text'