diff --git a/lam/HISTORY b/lam/HISTORY index 87d32675..8751d0f8 100644 --- a/lam/HISTORY +++ b/lam/HISTORY @@ -1,4 +1,5 @@ September 2017 6.1 + - Automatically trim input fields to avoid trailing/leading spaces - LAM Pro: -> Custom fields: support wildcards in text fields such as $firstname -> Custom fields: specify minimum/maximum count for multi-value entries diff --git a/lam/lib/html.inc b/lam/lib/html.inc index 3ccf5a34..762f7a4c 100644 --- a/lam/lib/html.inc +++ b/lam/lib/html.inc @@ -454,6 +454,8 @@ class htmlInputField extends htmlElement { protected $title = null; /** field ID that needs to have same value (e.g. password field) */ protected $sameValueFieldID = null; + /** marks the input field as auto trimmed (remove spaces at start/end) */ + protected $autoTrim = true; /** * Constructor @@ -486,6 +488,9 @@ class htmlInputField extends htmlElement { */ function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) { $this->cssClasses[] = 'ui-corner-all'; + if ($this->isAutoTrim()) { + $this->cssClasses[] = 'lam-autotrim'; + } if (isset($values[$this->fieldName])) { if (isObfuscatedText($values[$this->fieldName][0])) { $this->fieldValue = deobfuscateText($values[$this->fieldName][0]); @@ -777,6 +782,19 @@ class htmlInputField extends htmlElement { $this->setOnKeyUp('filterSelect(\'' . $this->fieldName . '\', \'' . $name . '\', event);'); } + /** + * Returns if the field content should be auto-trimmed (remove spaces at start/end). + * + * @return boolean auto-trim input + */ + protected function isAutoTrim() { + return $this->autoTrim && !$this->isPassword; + } + + public function disableAutoTrim() { + $this->autoTrim = false; + } + } /** diff --git a/lam/templates/lib/500_lam.js b/lam/templates/lib/500_lam.js index c1d8a3eb..2cef5f9e 100644 --- a/lam/templates/lib/500_lam.js +++ b/lam/templates/lib/500_lam.js @@ -759,9 +759,14 @@ window.lam.upload.uploadDone = function(jsonData) { else { top.location.href = '../lists/list.php?type=' + jsonData.typeId + '&uploadAllOk'; } -} +}; -jQuery(document).ready(function() { +window.lam.gui = window.lam.gui || {}; + +/** + * Resizes input fields etc. when they are marked as equally high. + */ +window.lam.gui.equalHeight = function() { var maxHeight = 0; jQuery('.lamEqualHeightTabContent').each(function() { if (jQuery(this).height() > maxHeight) { @@ -771,4 +776,22 @@ jQuery(document).ready(function() { jQuery('.lamEqualHeightTabContent').each(function() { jQuery(this).css({'height': maxHeight}); }); +}; + +window.lam.form = window.lam.form || {}; + +/** + * Trims all marked input elements on form submission. + */ +window.lam.form.autoTrim = function() { + jQuery('form').submit(function(e) { + jQuery('.lam-autotrim').each(function() { + this.value = String.trim(this.value); + }); + }); +}; + +jQuery(document).ready(function() { + window.lam.gui.equalHeight(); + window.lam.form.autoTrim(); });