From aa13b78838e406fa1aff8f2614d0aadaccf48bc0 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sun, 6 Apr 2008 04:01:28 +0000 Subject: [PATCH] Merged revisions 47499 via svnmerge from svn://svn.silverstripe.com/silverstripe/modules/sapphire/branches/2.2.0-mesq ........ r47499 | ischommer | 2007-12-22 17:23:26 +1300 (Sat, 22 Dec 2007) | 1 line added tabIndex ........ git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@52187 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/FormField.php | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) 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.