added auto-trimming

This commit is contained in:
Roland Gruber 2017-08-26 11:42:48 +02:00
parent 0c56824988
commit ec308f3b20
3 changed files with 44 additions and 2 deletions

View File

@ -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

View File

@ -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;
}
}
/**

View File

@ -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();
});