mirror of
https://github.com/processwire/processwire.git
synced 2025-08-18 12:31:17 +02:00
Add support for noTrim
option to InputfieldText/InputfieldTextarea per processwire/processwire-issues#459
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
* @property string $pattern HTML5 pattern attribute
|
* @property string $pattern HTML5 pattern attribute
|
||||||
* @property string $initValue Optional initial/default value
|
* @property string $initValue Optional initial/default value
|
||||||
* @property bool $stripTags Should HTML tags be stripped from value?
|
* @property bool $stripTags Should HTML tags be stripped from value?
|
||||||
|
* @property bool $noTrim By default whitespace is trimmed from value, set this to true to bypass that behavior (default=false).
|
||||||
* @property bool $useLanguages When combined with multi-language support, setting this to true will provide one input per language. Get/set each language value with the "value[languageID]" property, and just "value" for default language.
|
* @property bool $useLanguages When combined with multi-language support, setting this to true will provide one input per language. Get/set each language value with the "value[languageID]" property, and just "value" for default language.
|
||||||
* @property bool|int $requiredAttr When combined with "required" option, this also makes it use the HTML5 "required" attribute. (default=false)
|
* @property bool|int $requiredAttr When combined with "required" option, this also makes it use the HTML5 "required" attribute. (default=false)
|
||||||
* @property int $showCount Show a character counter (1) or word counter (2) or neither (0). Recommended value is 1 when using minlength or maxlength.
|
* @property int $showCount Show a character counter (1) or word counter (2) or neither (0). Recommended value is 1 when using minlength or maxlength.
|
||||||
@@ -51,6 +52,7 @@ class InputfieldText extends Inputfield {
|
|||||||
$this->set('requiredAttr', 0);
|
$this->set('requiredAttr', 0);
|
||||||
$this->set('initValue', ''); // optional initial value
|
$this->set('initValue', ''); // optional initial value
|
||||||
$this->set('stripTags', false); // strip tags from input?
|
$this->set('stripTags', false); // strip tags from input?
|
||||||
|
$this->set('noTrim', false);
|
||||||
$this->set('showCount', self::showCountNone);
|
$this->set('showCount', self::showCountNone);
|
||||||
|
|
||||||
// if multi-language, support placeholders for each language
|
// if multi-language, support placeholders for each language
|
||||||
@@ -163,7 +165,7 @@ class InputfieldText extends Inputfield {
|
|||||||
*
|
*
|
||||||
* @param array|string $key
|
* @param array|string $key
|
||||||
* @param array|int|string $value
|
* @param array|int|string $value
|
||||||
* @return $this
|
* @return Inputfield|InputfieldText|$this
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function setAttribute($key, $value) {
|
public function setAttribute($key, $value) {
|
||||||
@@ -195,6 +197,7 @@ class InputfieldText extends Inputfield {
|
|||||||
'maxLength' => $this->maxlength,
|
'maxLength' => $this->maxlength,
|
||||||
'maxBytes' => $this->maxlength*4,
|
'maxBytes' => $this->maxlength*4,
|
||||||
'stripTags' => false,
|
'stripTags' => false,
|
||||||
|
'trim' => $this->noTrim ? false : true,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,7 +254,7 @@ class InputfieldText extends Inputfield {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($maxlength > 0) {
|
if($maxlength > 0) {
|
||||||
$dirtyValue = trim($input->$name);
|
$dirtyValue = $this->noTrim ? (string) $input->$name : trim($input->$name);
|
||||||
$dirtyLength = $this->getValueLength($dirtyValue);
|
$dirtyLength = $this->getValueLength($dirtyValue);
|
||||||
if($dirtyLength > $maxlength) {
|
if($dirtyLength > $maxlength) {
|
||||||
$this->error(sprintf(
|
$this->error(sprintf(
|
||||||
|
@@ -110,6 +110,7 @@ class InputfieldTextarea extends InputfieldText {
|
|||||||
'maxLength' => $maxlength,
|
'maxLength' => $maxlength,
|
||||||
'maxBytes' => $maxlength*4,
|
'maxBytes' => $maxlength*4,
|
||||||
'stripTags' => false,
|
'stripTags' => false,
|
||||||
|
'trim' => $this->noTrim ? false : true
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
if(strpos($value, "\r\n") !== false) {
|
if(strpos($value, "\r\n") !== false) {
|
||||||
@@ -117,7 +118,7 @@ class InputfieldTextarea extends InputfieldText {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($this->stripTags) $value = strip_tags($value);
|
if($this->stripTags) $value = strip_tags($value);
|
||||||
return trim($value);
|
return $this->noTrim ? $value : trim($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user