diff --git a/forms/FormField.php b/forms/FormField.php
index 6f10c5df7..fe116967e 100644
--- a/forms/FormField.php
+++ b/forms/FormField.php
@@ -41,6 +41,13 @@ class FormField extends ViewableData {
*/
protected $leftTitle;
+ /**
+ * Set the "tabindex" HTML attribute on the field.
+ *
+ * @var int
+ */
+ protected $tabIndex;
+
/**
* Create a new field.
* @param name The internal field name, passed to forms.
@@ -77,6 +84,9 @@ class FormField extends ViewableData {
return $this->name;
}
+ function attrName() {
+ return $this->name;
+ }
/**
* Returns the field message, used by form validation
@@ -143,6 +153,36 @@ class FormField extends ViewableData {
$this->leftTitle = $val;
}
+ /**
+ * Set tabindex HTML attribute
+ * (defaults to none).
+ *
+ * @param int $index
+ */
+ public function setTabIndex($index) {
+ $this->tabIndex = $index;
+ }
+
+ /**
+ * Get tabindex (if previously set)
+ *
+ * @return int
+ */
+ public function getTabIndex() {
+ return $this->tabIndex;
+ }
+
+ /**
+ * Get tabindex HTML string
+ *
+ * @param int $increment Increase current tabindex by this value
+ * @return string
+ */
+ protected function getTabIndexHTML($increment = 0) {
+ $tabIndex = (int)$this->getTabIndex() + (int)$increment;
+ return (is_numeric($tabIndex)) ? ' tabindex = "' . $tabIndex . '"' : '';
+ }
+
/**
* Compiles all CSS-classes. Optionally includes a "nolabel"-class
* if no title was set on the formfield.
@@ -242,7 +282,7 @@ class FormField extends ViewableData {
if($this->value) $val = $this->dontEscape ? ($this->reserveNL?Convert::raw2xml($this->value):$this->value) : Convert::raw2xml($this->value);
else $val = '('._t('FormField.NONE', 'none').')';
$valforInput = $this->value ? Convert::raw2att($val) : "";
- return "id() . "\">$val\nname."\" value=\"".$valforInput."\" />";
+ return "id() . "\">$val\nname."\" value=\"".$valforInput."\"" . $this->getTabIndexHTML() . " />";
}
/**
* Returns a "Field Holder" for this field - used by templates.