From a975b8866136461ca636978bfeaa25fc71375c40 Mon Sep 17 00:00:00 2001 From: Saophalkun Ponlu Date: Tue, 16 May 2017 10:52:15 +1200 Subject: [PATCH] Pass autofocus flag to front-end --- src/Forms/FormField.php | 28 ++++++++++++++++++- .../FormSchemaTest/testGetNestedSchema.json | 7 +++++ .../Forms/FormSchemaTest/testGetSchema.json | 1 + .../FormSchemaTest/testSchemaValidation.json | 5 ++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/Forms/FormField.php b/src/Forms/FormField.php index 8aae63ea8..1d4fa9ad5 100644 --- a/src/Forms/FormField.php +++ b/src/Forms/FormField.php @@ -169,6 +169,11 @@ class FormField extends RequestHandler */ protected $disabled = false; + /** + * @var bool + */ + protected $autofocus = false; + /** * Custom validation message for the field. * @@ -716,7 +721,8 @@ class FormField extends RequestHandler 'class' => $this->extraClass(), 'id' => $this->ID(), 'disabled' => $this->isDisabled(), - 'readonly' => $this->isReadonly() + 'readonly' => $this->isReadonly(), + 'autofocus' => $this->isAutofocus() ); if ($this->Required()) { @@ -1222,6 +1228,25 @@ class FormField extends RequestHandler return $this; } + /** + * @return bool + */ + public function isAutofocus() { + return $this->autofocus; + } + + /** + * Sets a autofocus flag on this FormField. + * + * @param bool $autofocus + * @return $this + */ + public function setAutofocus($autofocus) + { + $this->autofocus = $autofocus; + return $this; + } + /** * Returns a read-only version of this field. * @@ -1560,6 +1585,7 @@ class FormField extends RequestHandler 'customValidationMessage' => $this->getCustomValidationMessage(), 'validation' => $this->getSchemaValidation(), 'attributes' => [], + 'autoFocus' => $this->isAutofocus(), 'data' => [], ]; } diff --git a/tests/php/Forms/FormSchemaTest/testGetNestedSchema.json b/tests/php/Forms/FormSchemaTest/testGetNestedSchema.json index dc060b0d5..6e6b70118 100644 --- a/tests/php/Forms/FormSchemaTest/testGetNestedSchema.json +++ b/tests/php/Forms/FormSchemaTest/testGetNestedSchema.json @@ -28,6 +28,7 @@ "leftTitle": null, "readOnly": false, "disabled": false, + "autoFocus": false, "customValidationMessage": "", "attributes": [], "data": [], @@ -48,6 +49,7 @@ "leftTitle": null, "readOnly": false, "disabled": false, + "autoFocus": false, "customValidationMessage": "", "attributes": [], "data": [], @@ -70,6 +72,7 @@ "leftTitle": null, "readOnly": false, "disabled": false, + "autoFocus": false, "customValidationMessage": "", "attributes": { "type": "submit" @@ -94,6 +97,7 @@ "leftTitle": null, "readOnly": false, "disabled": false, + "autoFocus": false, "customValidationMessage": "", "attributes": { "type": "button" @@ -118,6 +122,7 @@ "leftTitle": null, "readOnly": null, "disabled": false, + "autoFocus": false, "customValidationMessage": "", "attributes": [], "data": { @@ -149,6 +154,7 @@ "leftTitle": null, "readOnly": false, "disabled": false, + "autoFocus": false, "customValidationMessage": "", "attributes": { "type": "submit" @@ -173,6 +179,7 @@ "leftTitle": null, "readOnly": false, "disabled": false, + "autoFocus": false, "customValidationMessage": "", "attributes": { "type": "submit" diff --git a/tests/php/Forms/FormSchemaTest/testGetSchema.json b/tests/php/Forms/FormSchemaTest/testGetSchema.json index fed186457..57a2ef642 100644 --- a/tests/php/Forms/FormSchemaTest/testGetSchema.json +++ b/tests/php/Forms/FormSchemaTest/testGetSchema.json @@ -28,6 +28,7 @@ "leftTitle": null, "readOnly": false, "disabled": false, + "autoFocus": false, "customValidationMessage": "", "attributes": [], "data": [], diff --git a/tests/php/Forms/FormSchemaTest/testSchemaValidation.json b/tests/php/Forms/FormSchemaTest/testSchemaValidation.json index 69d4c5476..09744bbfa 100644 --- a/tests/php/Forms/FormSchemaTest/testSchemaValidation.json +++ b/tests/php/Forms/FormSchemaTest/testSchemaValidation.json @@ -28,6 +28,7 @@ "leftTitle": null, "readOnly": false, "disabled": false, + "autoFocus": false, "customValidationMessage": "", "validation": { "required": true, @@ -54,6 +55,7 @@ "leftTitle": null, "readOnly": false, "disabled": false, + "autoFocus": false, "customValidationMessage": "", "validation": { "date": true @@ -80,6 +82,7 @@ "leftTitle": null, "readOnly": false, "disabled": false, + "autoFocus": false, "customValidationMessage": "", "validation": { "numeric": true @@ -102,6 +105,7 @@ "leftTitle": null, "readOnly": false, "disabled": false, + "autoFocus": false, "customValidationMessage": "", "validation": { "currency": true @@ -124,6 +128,7 @@ "leftTitle": null, "readOnly": false, "disabled": false, + "autoFocus": false, "customValidationMessage": "", "validation": [], "attributes": [],