From 37e032df869719e5987ec8fdd87833ea64a3246a Mon Sep 17 00:00:00 2001 From: Tom Densham Date: Thu, 3 Oct 2013 15:26:31 +0100 Subject: [PATCH] API: Change CreditCardField to use AttributeHTML --- forms/CreditCardField.php | 25 ++++++++++++++++++------- templates/forms/CreditCardField.ss | 11 +++++++---- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/forms/CreditCardField.php b/forms/CreditCardField.php index e30b3687a..aa29d6422 100644 --- a/forms/CreditCardField.php +++ b/forms/CreditCardField.php @@ -9,21 +9,32 @@ * @subpackage fields-formattedinput */ class CreditCardField extends TextField { + + /** + * Add default attributes for use on all inputs. + * + * @return array List of attributes + */ + public function getAttributes() { + return array_merge( + parent::getAttributes(), + array( + 'autocomplete' => 'off', + 'maxlength' => 4, + 'size' => 4 + ) + ); + } public function Field($properties = array()) { $parts = $this->value; if(!is_array($parts)) $parts = explode("\n", chunk_split($parts,4,"\n")); $parts = array_pad($parts, 4, ""); - // TODO Mark as disabled/readonly $properties['ValueOne'] = $parts[0]; $properties['ValueTwo'] = $parts[1]; $properties['ValueThree'] = $parts[2]; $properties['ValueFour'] = $parts[3]; - $properties['TabIndexOne'] = $this->getTabIndexHTML(0); - $properties['TabIndexTwo'] = $this->getTabIndexHTML(1); - $properties['TabIndexThree'] = $this->getTabIndexHTML(2); - $properties['TabIndexFour'] = $this->getTabIndexHTML(3); return parent::Field($properties); } @@ -34,14 +45,14 @@ class CreditCardField extends TextField { * @param int $increment Increase current tabindex by this value * @return string */ - protected function getTabIndexHTML($increment = 0) { + public function getTabIndexHTML($increment = 0) { // we can't add a tabindex if there hasn't been one set yet. if($this->getAttribute('tabindex') === null) return false; $tabIndex = (int)$this->getAttribute('tabindex') + (int)$increment; return (is_numeric($tabIndex)) ? ' tabindex = "' . $tabIndex . '"' : ''; } - + public function dataValue() { if(is_array($this->value)) return implode("", $this->value); else return $this->value; diff --git a/templates/forms/CreditCardField.ss b/templates/forms/CreditCardField.ss index 588a15f5b..9876d238a 100644 --- a/templates/forms/CreditCardField.ss +++ b/templates/forms/CreditCardField.ss @@ -1,6 +1,9 @@ - - - - - - - + + - + + - + + - + \ No newline at end of file