support number fields with min/max

This commit is contained in:
Roland Gruber 2017-11-19 10:13:41 +01:00
parent 56fe32cad6
commit d0f6befa7e
1 changed files with 28 additions and 1 deletions

View File

@ -455,6 +455,10 @@ class htmlInputField extends htmlElement {
protected $sameValueFieldID = null; protected $sameValueFieldID = null;
/** marks the input field as auto trimmed (remove spaces at start/end) */ /** marks the input field as auto trimmed (remove spaces at start/end) */
protected $autoTrim = true; protected $autoTrim = true;
/** minimum value */
protected $minValue = null;
/** maximum value */
protected $maxValue = null;
/** /**
* Constructor * Constructor
@ -505,6 +509,14 @@ class htmlInputField extends htmlElement {
if ($this->validationRule != null) { if ($this->validationRule != null) {
$validators[] = 'custom[' . $this->validationRule . ']'; $validators[] = 'custom[' . $this->validationRule . ']';
} }
$min = '';
if ($this->minValue !== null) {
$min = ' min="' . $this->minValue . '"';
}
$max = '';
if ($this->maxValue !== null) {
$max = ' max="' . $this->maxValue . '"';
}
// print input field // print input field
$class = ''; $class = '';
if (sizeof($validators) > 0) { if (sizeof($validators) > 0) {
@ -533,6 +545,9 @@ class htmlInputField extends htmlElement {
if ($this->isPassword) { if ($this->isPassword) {
$inputType = 'password'; $inputType = 'password';
} }
elseif (($this->minValue !== null) || ($this->maxValue !== null)) {
$inputType = 'number';
}
$disabled = ''; $disabled = '';
if (!$this->isEnabled) { if (!$this->isEnabled) {
$disabled = ' disabled'; $disabled = ' disabled';
@ -549,7 +564,8 @@ class htmlInputField extends htmlElement {
if (!empty($this->title)) { if (!empty($this->title)) {
$title = ' title="' . $this->title . '"'; $title = ' title="' . $this->title . '"';
} }
echo '<input type="' . $inputType . '"' . $class . $name . $id . $value . $maxLength . $size . $fieldTabIndex . $onKeyPress . $onKeyUp . $title . $disabled . '>'; echo '<input type="' . $inputType . '"' . $class . $name . $id . $value . $maxLength
. $min . $max . $size . $fieldTabIndex . $onKeyPress . $onKeyUp . $title . $disabled . '>';
// autocompletion // autocompletion
if ($this->autocomplete) { if ($this->autocomplete) {
echo "<script type=\"text/javascript\">\n"; echo "<script type=\"text/javascript\">\n";
@ -703,6 +719,17 @@ class htmlInputField extends htmlElement {
$this->validationRule = $rule; $this->validationRule = $rule;
} }
/**
* Sets the field as number field with minimum and maximum values.
*
* @param integer $minimum minimum
* @param integer $maximum maximum
*/
public function setMinimumAndMaximumNumber($minimum, $maximum = null) {
$this->minValue = $minimum;
$this->maxValue = $maximum;
}
/** /**
* Enables autocompletion for this input field. * Enables autocompletion for this input field.
* *