From 37e5b2328fa8526f8cbd5f2c2c73c824c8781bb1 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sat, 20 Jun 2015 12:00:37 +1000 Subject: [PATCH] Form text/password/number fields now support maxlength attribute - Fixes #1210 --- CHANGELOG.md | 3 ++ modules/backend/classes/FormField.php | 31 ++++++++++++++++--- .../widgets/form/partials/_field_number.htm | 2 +- .../widgets/form/partials/_field_password.htm | 2 +- .../widgets/form/partials/_field_text.htm | 2 +- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 344be1782..226f40afa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +* **Build 27x** (2015-06-xx) + - Protected images and their thumbnails are now supported in the back-end. + * **Build 271** (2015-06-20) - File Upload form widget can now specify `mimeTypes` to define MIME types that are accepted by the uploader, either as file extension or fully qualified name. diff --git a/modules/backend/classes/FormField.php b/modules/backend/classes/FormField.php index 62e122f00..4ef1aeac4 100644 --- a/modules/backend/classes/FormField.php +++ b/modules/backend/classes/FormField.php @@ -341,7 +341,7 @@ class FormField * - field: Attributes are added to the form field element (input, select, textarea, etc) * - container: Attributes are added to the form field container (div.form-group) * @param array $items - * @param strubg $position + * @param string $position * @return void */ public function attributes($items, $position = 'field') @@ -359,6 +359,23 @@ class FormField foreach ($items as $_position => $_items) { $this->attributes($_items, $_position); } + + return $this; + } + + /** + * Checks if the field has the supplied [unfiltered] attribute. + * @param string $name + * @param string $position + * @return bool + */ + public function hasAttribute($name, $position = 'field') + { + if (!isset($this->attributes[$position])) { + return false; + } + + return array_key_exists($name, $this->attributes[$position]); } /** @@ -402,20 +419,23 @@ class FormField */ protected function filterTriggerAttributes($attributes, $position = 'field') { - if (!$this->trigger || !is_array($this->trigger)) + if (!$this->trigger || !is_array($this->trigger)) { return $attributes; + } $triggerAction = array_get($this->trigger, 'action'); $triggerField = array_get($this->trigger, 'field'); $triggerCondition = array_get($this->trigger, 'condition'); // Apply these to container - if (in_array($triggerAction, ['hide', 'show']) && $position != 'container') + if (in_array($triggerAction, ['hide', 'show']) && $position != 'container') { return $attributes; + } // Apply these to field/input - if (in_array($triggerAction, ['enable', 'disable', 'empty']) && $position != 'field') + if (in_array($triggerAction, ['enable', 'disable', 'empty']) && $position != 'field') { return $attributes; + } if ($this->arrayName) { $fullTriggerField = $this->arrayName.'['.implode('][', HtmlHelper::nameToArray($triggerField)).']'; @@ -443,8 +463,9 @@ class FormField */ protected function filterPresetAttributes($attributes, $position = 'field') { - if (!$this->preset || $position != 'field') + if (!$this->preset || $position != 'field') { return $attributes; + } if (!is_array($this->preset)) { $this->preset = ['field' => $this->preset, 'type' => 'slug']; diff --git a/modules/backend/widgets/form/partials/_field_number.htm b/modules/backend/widgets/form/partials/_field_number.htm index 48d944798..5e5b3fa64 100644 --- a/modules/backend/widgets/form/partials/_field_number.htm +++ b/modules/backend/widgets/form/partials/_field_number.htm @@ -10,8 +10,8 @@ placeholder="placeholder)) ?>" class="form-control" autocomplete="off" - maxlength="255" pattern="-?\d+(\.\d+)?" + hasAttribute('maxlength') ? '' : 'maxlength="255"' ?> getAttributes() ?> /> diff --git a/modules/backend/widgets/form/partials/_field_password.htm b/modules/backend/widgets/form/partials/_field_password.htm index d1b10271f..578f660d2 100644 --- a/modules/backend/widgets/form/partials/_field_password.htm +++ b/modules/backend/widgets/form/partials/_field_password.htm @@ -9,7 +9,7 @@ value="" class="form-control" autocomplete="off" - maxlength="255" + hasAttribute('maxlength') ? '' : 'maxlength="255"' ?> getAttributes() ?> /> \ No newline at end of file diff --git a/modules/backend/widgets/form/partials/_field_text.htm b/modules/backend/widgets/form/partials/_field_text.htm index c622ea8ed..0ac43a75a 100644 --- a/modules/backend/widgets/form/partials/_field_text.htm +++ b/modules/backend/widgets/form/partials/_field_text.htm @@ -10,7 +10,7 @@ placeholder="placeholder)) ?>" class="form-control" autocomplete="off" - maxlength="255" + hasAttribute('maxlength') ? '' : 'maxlength="255"' ?> getAttributes() ?> /> \ No newline at end of file