diff --git a/layouts/joomla/form/field/color/advanced.php b/layouts/joomla/form/field/color/advanced.php index fcdb9a8f05a99..6962e62734a80 100644 --- a/layouts/joomla/form/field/color/advanced.php +++ b/layouts/joomla/form/field/color/advanced.php @@ -43,6 +43,7 @@ * @var array $checked Is this field checked? * @var array $position Is this field checked? * @var array $control Is this field checked? + * @var array $dataAttribute Miscellaneous data attribute for eg, data-* */ if ($validate !== 'color' && in_array($format, array('rgb', 'rgba'), true)) @@ -67,7 +68,14 @@ $autocomplete = ! $autocomplete ? ' autocomplete="off"' : ''; // Force LTR input value in RTL, due to display issues with rgba/hex colors -$direction = $lang->isRtl() ? ' dir="ltr" style="text-align:right"' : ''; +$direction = $lang->isRtl() ? ' dir="ltr" style="text-align:right"' : ''; + +$dataAttribute = ''; + +foreach ($dataAttributes as $key => $value) +{ + $dataAttribute .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; +} // Including fallback code for HTML5 non supported browsers. JHtml::_('jquery.framework'); @@ -90,5 +98,6 @@ $format, $keywords, $direction, - $validate; + $validate, + $dataAttribute; ?>/> diff --git a/layouts/joomla/form/field/color/simple.php b/layouts/joomla/form/field/color/simple.php index 04016ccd7b3b8..9b6681e1299e6 100644 --- a/layouts/joomla/form/field/color/simple.php +++ b/layouts/joomla/form/field/color/simple.php @@ -43,11 +43,19 @@ * @var array $checked Is this field checked? * @var array $position Is this field checked? * @var array $control Is this field checked? + * @var array $dataAttribute Miscellaneous data attribute for eg, data-*. */ -$class = ' class="' . trim('simplecolors chzn-done ' . $class) . '"'; -$disabled = $disabled ? ' disabled' : ''; -$readonly = $readonly ? ' readonly' : ''; +$class = ' class="' . trim('simplecolors chzn-done ' . $class) . '"'; +$disabled = $disabled ? ' disabled' : ''; +$readonly = $readonly ? ' readonly' : ''; + +$dataAttribute = ''; + +foreach ($dataAttributes as $key => $value) +{ + $dataAttribute .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; +} // Include jQuery JHtml::_('jquery.framework'); @@ -57,7 +65,7 @@ JHtml::_('script', 'system/color-field-init.min.js', array('version' => 'auto', 'relative' => true)); ?> + />
diff --git a/layouts/joomla/form/field/hidden.php b/layouts/joomla/form/field/hidden.php index db85e484662a9..1b4192915083d 100644 --- a/layouts/joomla/form/field/hidden.php +++ b/layouts/joomla/form/field/hidden.php @@ -41,14 +41,21 @@ * @var boolean $hasValue Has this field a value assigned? * @var array $options Options available for this field. * @var array $inputType Options available for this field. + * @var array $dataAttribute Miscellaneous data attribute for eg, data-*. */ // Initialize some field attributes. -$class = !empty($class) ? ' class="' . $class . '"' : ''; -$disabled = $disabled ? ' disabled' : ''; -$onchange = $onchange ? ' onchange="' . $onchange . '"' : ''; +$class = !empty($class) ? ' class="' . $class . '"' : ''; +$disabled = $disabled ? ' disabled' : ''; +$onchange = $onchange ? ' onchange="' . $onchange . '"' : ''; +$dataAttribute = ''; + +foreach ($dataAttributes as $key => $value) +{ + $dataAttribute .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; +} ?> /> +echo htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); ?>" /> diff --git a/layouts/joomla/form/field/meter.php b/layouts/joomla/form/field/meter.php index 9e74217f5e909..8b93d78b33c89 100644 --- a/layouts/joomla/form/field/meter.php +++ b/layouts/joomla/form/field/meter.php @@ -47,6 +47,7 @@ * @var string $min The minimum value. * @var string $max The maximum value. * @var string $step The step value. + * @var array $dataAttribute Miscellaneous data attribute for eg, data-*. */ // Initialize some field attributes. @@ -65,8 +66,16 @@ $data .= ' data-step="' . $step . '"'; $data .= ' data-value="' . $value . '"'; +$dataAttribute = ''; + +foreach ($dataAttributes as $key => $value) +{ + $dataAttribute .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; +} + $attributes = array( $class, + $dataAttribute, !empty($width) ? ' style="width:' . $width . ';"' : '', $data ); diff --git a/layouts/joomla/form/field/number.php b/layouts/joomla/form/field/number.php index 3dad2b2d7ba5e..2b8e9ad9b758b 100644 --- a/layouts/joomla/form/field/number.php +++ b/layouts/joomla/form/field/number.php @@ -43,16 +43,25 @@ * @var array $inputType Options available for this field. * @var array $spellcheck Options available for this field. * @var string $accept File types that are accepted. + * @var array $dataAttribute Miscellaneous data attribute for eg, data-*. */ $autocomplete = !$autocomplete ? ' autocomplete="off"' : ' autocomplete="' . $autocomplete . '"'; $autocomplete = $autocomplete == ' autocomplete="on"' ? '' : $autocomplete; +$dataAttribute = ''; + +foreach ($dataAttributes as $key => $value) +{ + $dataAttribute .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; +} + $attributes = array( !empty($class) ? 'class="' . $class . '"' : '', !empty($size) ? 'size="' . $size . '"' : '', $disabled ? 'disabled' : '', $readonly ? 'readonly' : '', + $dataAttribute, strlen($hint) ? 'placeholder="' . htmlspecialchars($hint, ENT_COMPAT, 'UTF-8') . '"' : '', !empty($onchange) ? 'onchange="' . $onchange . '"' : '', isset($max) ? 'max="' . $max . '"' : '', diff --git a/layouts/joomla/form/field/password.php b/layouts/joomla/form/field/password.php index ea434d488f336..7183f924a2f8b 100644 --- a/layouts/joomla/form/field/password.php +++ b/layouts/joomla/form/field/password.php @@ -42,6 +42,7 @@ * @var array $options Options available for this field. * @var array $inputType Options available for this field. * @var string $accept File types that are accepted. + * @var array $dataAttribute Miscellaneous data attribute for eg, data-*. */ if ($meter) @@ -67,11 +68,19 @@ JHtml::_('jquery.framework'); JHtml::_('script', 'system/html5fallback.js', array('version' => 'auto', 'relative' => true, 'conditional' => 'lt IE 9')); +$dataAttribute = ''; + +foreach ($dataAttributes as $key => $value) +{ + $dataAttribute .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; +} + $attributes = array( strlen($hint) ? 'placeholder="' . htmlspecialchars($hint, ENT_COMPAT, 'UTF-8') . '"' : '', !$autocomplete ? 'autocomplete="off"' : '', !empty($class) ? 'class="' . $class . '"' : '', $readonly ? 'readonly' : '', + $dataAttribute, $disabled ? 'disabled' : '', !empty($size) ? 'size="' . $size . '"' : '', !empty($maxLength) ? 'maxlength="' . $maxLength . '"' : '', diff --git a/layouts/joomla/form/field/radio.php b/layouts/joomla/form/field/radio.php index a2ae3f4595853..4e36a581c3125 100644 --- a/layouts/joomla/form/field/radio.php +++ b/layouts/joomla/form/field/radio.php @@ -38,6 +38,7 @@ * @var string $validate Validation rules to apply. * @var string $value Value attribute of the field. * @var array $options Options available for this field. + * @var array $dataAttribute Miscellaneous data attribute for eg, data-*. */ // Including fallback code for HTML5 non supported browsers. @@ -76,7 +77,13 @@ $onchange = !empty($option->onchange) ? 'onchange="' . $option->onchange . '"' : ''; $oid = $id . $i; $ovalue = htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8'); - $attributes = array_filter(array($checked, $optionClass, $disabled, $style, $onchange, $onclick)); + $dataAttribute = ''; + + foreach ($option->dataAttributes as $key => $value) + { + $dataAttribute .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; + } + $attributes = array_filter(array($checked, $optionClass, $disabled, $style, $onchange, $onclick, $dataAttribute)); ?> diff --git a/layouts/joomla/form/field/range.php b/layouts/joomla/form/field/range.php index 2806e3e909b29..fd866ae14be1a 100644 --- a/layouts/joomla/form/field/range.php +++ b/layouts/joomla/form/field/range.php @@ -42,16 +42,25 @@ * @var array $options Options available for this field. * @var array $inputType Options available for this field. * @var string $accept File types that are accepted. + * @var array $dataAttribute Miscellaneous data attribute for eg, data-*. */ // Including fallback code for HTML5 non supported browsers. JHtml::_('jquery.framework'); JHtml::_('script', 'system/html5fallback.js', array('version' => 'auto', 'relative' => true, 'conditional' => 'lt IE 9')); +$dataAttribute = ''; + +foreach ($dataAttributes as $key => $value) +{ + $dataAttribute .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; +} + // Initialize some field attributes. $attributes = array( $class ? 'class="' . $class . '"' : '', $disabled ? 'disabled' : '', + $dataAttribute, $readonly ? 'readonly' : '', !empty($onchange) ? 'onchange="' . $onchange . '"' : '', !empty($max) ? 'max="' . $max . '"' : '', diff --git a/layouts/joomla/form/field/tel.php b/layouts/joomla/form/field/tel.php index 468483fad7190..217371807270f 100644 --- a/layouts/joomla/form/field/tel.php +++ b/layouts/joomla/form/field/tel.php @@ -43,6 +43,7 @@ * @var array $inputType Options available for this field. * @var string $accept File types that are accepted. * @var integer $maxLength The maximum length that the field shall accept. + * @var array $dataAttribute Miscellaneous data attribute for eg, data-*. */ // Including fallback code for HTML5 non supported browsers. @@ -52,9 +53,17 @@ $autocomplete = !$autocomplete ? ' autocomplete="off"' : ' autocomplete="' . $autocomplete . '"'; $autocomplete = $autocomplete == ' autocomplete="on"' ? '' : $autocomplete; +$dataAttribute = ''; + +foreach ($dataAttributes as $key => $value) +{ + $dataAttribute .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; +} + $attributes = array( !empty($size) ? 'size="' . $size . '"' : '', $disabled ? 'disabled' : '', + $dataAttribute, $readonly ? 'readonly' : '', strlen($hint) ? 'placeholder="' . htmlspecialchars($hint, ENT_COMPAT, 'UTF-8') . '"' : '', $autocomplete, diff --git a/layouts/joomla/form/field/text.php b/layouts/joomla/form/field/text.php index 4ea1c423ccf41..53da4ccb53790 100644 --- a/layouts/joomla/form/field/text.php +++ b/layouts/joomla/form/field/text.php @@ -42,6 +42,7 @@ * @var array $options Options available for this field. * @var array $inputType Options available for this field. * @var string $accept File types that are accepted. + * @var array $dataAttribute Miscellaneous data attribute for eg, data-*. */ // Including fallback code for HTML5 non supported browsers. @@ -58,10 +59,18 @@ $autocomplete = !$autocomplete ? ' autocomplete="off"' : ' autocomplete="' . $autocomplete . '"'; $autocomplete = $autocomplete === ' autocomplete="on"' ? '' : $autocomplete; +$dataAttribute = ''; + +foreach ($dataAttributes as $key => $value) +{ + $dataAttribute .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; +} + $attributes = array( !empty($class) ? 'class="' . $class . '"' : '', !empty($size) ? 'size="' . $size . '"' : '', $disabled ? 'disabled' : '', + $dataAttribute, $readonly ? 'readonly' : '', $list, strlen($hint) ? 'placeholder="' . htmlspecialchars($hint, ENT_COMPAT, 'UTF-8') . '"' : '', diff --git a/layouts/joomla/form/field/textarea.php b/layouts/joomla/form/field/textarea.php index 1a18916ff0ea7..481ba8ed3a0c4 100644 --- a/layouts/joomla/form/field/textarea.php +++ b/layouts/joomla/form/field/textarea.php @@ -42,6 +42,7 @@ * @var array $options Options available for this field. * @var array $inputType Options available for this field. * @var string $accept File types that are accepted. + * @var array $dataAttribute Miscellaneous data attribute for eg, data-*. */ // Including fallback code for HTML5 non supported browsers. @@ -52,12 +53,20 @@ $autocomplete = !$autocomplete ? 'autocomplete="off"' : 'autocomplete="' . $autocomplete . '"'; $autocomplete = $autocomplete == 'autocomplete="on"' ? '' : $autocomplete; +$dataAttribute = ''; + +foreach ($dataAttributes as $key => $value) +{ + $dataAttribute .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; +} + $attributes = array( $columns ?: '', $rows ?: '', !empty($class) ? 'class="' . $class . '"' : '', strlen($hint) ? 'placeholder="' . htmlspecialchars($hint, ENT_COMPAT, 'UTF-8') . '"' : '', $disabled ? 'disabled' : '', + $dataAttribute, $readonly ? 'readonly' : '', $onchange ? 'onchange="' . $onchange . '"' : '', $onclick ? 'onclick="' . $onclick . '"' : '', diff --git a/layouts/joomla/form/field/url.php b/layouts/joomla/form/field/url.php index a4b3f8c38c30e..814841559459a 100644 --- a/layouts/joomla/form/field/url.php +++ b/layouts/joomla/form/field/url.php @@ -42,6 +42,7 @@ * @var array $options Options available for this field. * @var array $inputType Options available for this field. * @var string $accept File types that are accepted. + * @var array $dataAttribute Miscellaneous data attribute for eg, data-* */ // Including fallback code for HTML5 non supported browsers. @@ -51,10 +52,18 @@ $autocomplete = !$autocomplete ? ' autocomplete="off"' : ' autocomplete="' . $autocomplete . '"'; $autocomplete = $autocomplete === ' autocomplete="on"' ? '' : $autocomplete; +$dataAttribute = ''; + +foreach ($dataAttributes as $key => $value) +{ + $dataAttribute .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; +} + $attributes = array( !empty($size) ? ' size="' . $size . '"' : '', $disabled ? ' disabled' : '', $readonly ? ' readonly' : '', + $dataAttribute, strlen($hint) ? ' placeholder="' . htmlspecialchars($hint, ENT_COMPAT, 'UTF-8') . '"' : '', $autocomplete, $autofocus ? ' autofocus' : '', diff --git a/libraries/joomla/form/fields/accesslevel.php b/libraries/joomla/form/fields/accesslevel.php index b05a06a7ab790..5478a0346fa0a 100644 --- a/libraries/joomla/form/fields/accesslevel.php +++ b/libraries/joomla/form/fields/accesslevel.php @@ -51,6 +51,12 @@ protected function getInput() // Initialize JavaScript field attributes. $attr .= $this->onchange ? ' onchange="' . $this->onchange . '"' : ''; + // Data attributes - data-* + foreach ($this->dataAttributes as $key => $value) + { + $attr .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; + } + // Get the field options. $options = $this->getOptions(); diff --git a/libraries/joomla/form/fields/checkbox.php b/libraries/joomla/form/fields/checkbox.php index 2f0aade22aa70..2d8a55d9fe8eb 100644 --- a/libraries/joomla/form/fields/checkbox.php +++ b/libraries/joomla/form/fields/checkbox.php @@ -141,12 +141,20 @@ protected function getInput() $onclick = !empty($this->onclick) ? ' onclick="' . $this->onclick . '"' : ''; $onchange = !empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : ''; + // Initialize JavaScript field data attributes. For eg, data-action-type="click" + $dataAttribute = ''; + + foreach ($this->dataAttributes as $key => $value) + { + $dataAttribute .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; + } + // Including fallback code for HTML5 non supported browsers. JHtml::_('jquery.framework'); JHtml::_('script', 'system/html5fallback.js', array('version' => 'auto', 'relative' => true, 'conditional' => 'lt IE 9')); return ''; + . $required . $autofocus . $dataAttribute . ' />'; } } diff --git a/libraries/joomla/form/fields/groupedlist.php b/libraries/joomla/form/fields/groupedlist.php index fbc238097c292..2cbefa4572fc7 100644 --- a/libraries/joomla/form/fields/groupedlist.php +++ b/libraries/joomla/form/fields/groupedlist.php @@ -158,6 +158,12 @@ protected function getInput() // Initialize JavaScript field attributes. $attr .= !empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : ''; + // Data attributes - data-* + foreach ($this->dataAttributes as $key => $value) + { + $attr .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; + } + // Get the field groups. $groups = (array) $this->getGroups(); diff --git a/libraries/joomla/form/fields/list.php b/libraries/joomla/form/fields/list.php index fcdcab4cd4937..c1ee8e59d68bc 100644 --- a/libraries/joomla/form/fields/list.php +++ b/libraries/joomla/form/fields/list.php @@ -54,6 +54,12 @@ protected function getInput() // Initialize JavaScript field attributes. $attr .= $this->onchange ? ' onchange="' . $this->onchange . '"' : ''; + // Data attributes - data-* + foreach ($this->dataAttributes as $key => $value) + { + $attr .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; + } + // Get the field options. $options = (array) $this->getOptions(); diff --git a/libraries/joomla/form/fields/usergroup.php b/libraries/joomla/form/fields/usergroup.php index 8b37d8e9b508e..9537c24fe21a0 100644 --- a/libraries/joomla/form/fields/usergroup.php +++ b/libraries/joomla/form/fields/usergroup.php @@ -53,6 +53,12 @@ protected function getInput() $attr .= !empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : ''; $attr .= !empty($this->onclick) ? ' onclick="' . $this->onclick . '"' : ''; + // Data attributes - data-* + foreach ($this->dataAttributes as $key => $value) + { + $attr .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; + } + // Iterate through the children and build an array of options. foreach ($this->element->children() as $option) { diff --git a/libraries/src/Form/FormField.php b/libraries/src/Form/FormField.php index eda262c2bd0a8..a2f46dbeaa1ad 100644 --- a/libraries/src/Form/FormField.php +++ b/libraries/src/Form/FormField.php @@ -345,6 +345,16 @@ abstract class FormField */ protected $renderLabelLayout = 'joomla.form.renderlabel'; + /** + * The data-attribute name and values of the form field. + * For example, data-action-type="click" data-action-type="change" + * + * @var array + * + * @since __DEPLOY_VERSION__ + */ + protected $dataAttributes = array(); + /** * Method to instantiate the form field object. * @@ -438,6 +448,13 @@ public function __get($name) case 'title': return $this->getTitle(); + + default: + // Check for data attribute + if (strpos($name, "data-") === 0 && array_key_exists($name, $this->dataAttributes)) + { + return $this->dataAttributes[$name]; + } } return; @@ -533,13 +550,21 @@ public function __set($name, $value) break; default: - if (property_exists(__CLASS__, $name)) + // Detect data attribute(s) + if (strpos($name, "data-") === 0) { - \JLog::add("Cannot access protected / private property $name of " . __CLASS__); + $this->dataAttributes[$name] = $value; } else { - $this->$name = $value; + if (property_exists(__CLASS__, $name)) + { + \JLog::add("Cannot access protected / private property $name of " . __CLASS__); + } + else + { + $this->$name = $value; + } } } } @@ -609,6 +634,16 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) $this->value = $value; } + // Lets detect miscellaneous data attribute. For eg, data-* + foreach ($this->element->attributes() as $key => $value) + { + if (strpos($key, "data-") === 0) + { + // Data attribute key value pair + $this->dataAttributes[$key] = $value; + } + } + foreach ($attributes as $attributeName) { $this->__set($attributeName, $element[$attributeName]); @@ -632,6 +667,18 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) return true; } + /** + * Method to get data attributes. For example, data-user-type + * + * @return array list of data attribute(s) + * + * @since __DEPLOY_VERSION__ + */ + public function getDataAttributes() + { + return $this->dataAttributes; + } + /** * Simple method to set the value * @@ -1025,6 +1072,7 @@ protected function getLayoutData() 'spellcheck' => $this->spellcheck, 'validate' => $this->validate, 'value' => $this->value, + 'dataAttributes' => $this->dataAttributes, ); }