11namespace Depage\HtmlForm\Elements;
71 parent::setDefaults();
73 $this->defaults[
'defaultValue'] = 0;
74 $this->defaults[
'min'] =
null;
75 $this->defaults[
'max'] =
null;
76 $this->defaults[
'step'] =
null;
77 $this->defaults[
'errorMessage'] = _(
'Please enter a valid number');
88 $type = strtolower($this->type);
91 $label = $this->htmlLabel();
100 return "<p {$wrapperAttributes}>" .
102 "<span class=\"depage-label\">{$label}{$marker}</span>" .
103 "<input name=\"{$this->name}\" type=\"{$type}\"{$max}{$min}{$step}{$inputAttributes} value=\"{$value}\">" .
118 return ($this->min ===
null) ?
"" :
" min=\"" . $this->
htmlEscape($this->min) .
"\"";
128 return ($this->max ===
null) ?
"" :
" max=\"" . $this->
htmlEscape($this->max) .
"\"";
138 return ($this->step ===
null) ?
"" :
" step=\"" . $this->
htmlEscape($this->step) .
"\"";
155 return $this->validator->validate($this->value, $parameters);
169 $pString = str_replace(
" ",
"", $ptString);
172 if (substr_count($pString,
",") > 1) {
173 $pString = str_replace(
",",
"", $pString);
175 if (substr_count($pString,
".") > 1) {
176 $pString = str_replace(
".",
"", $pString);
180 $commaset = strrpos($pString,
',');
181 $pointset = strrpos($pString,
'.');
184 if ($commaset > $pointset) {
185 $pString = str_replace(
".",
"", $pString);
186 } elseif ($commaset < $pointset) {
187 $pString = str_replace(
",",
"", $pString);
191 $pString = str_replace(
",",
".", $pString);
193 if ($pString !==
"" && preg_match(
"/^[-+]?\d*\.?\d*$/", $pString)) {
194 $this->value = (float) $pString;
212 if ($this->step !==
null && ($pos = strpos($this->step,
".")) !==
false) {
213 $decimals = strlen(substr($this->step, $pos + 1));
216 return number_format($this->
getValue(), $decimals,
'.',
'');
230 && $this->value !== 0
231 && $this->value !== .0
htmlEscape(array|string $options=[])
Escapes HTML in strings and arrays of strings.
$value
Input elements's value.
$label
Input element - HTML label.
$errorMessage
Message that gets displayed in case of invalid input.
htmlHelpMessage()
Returns HTML-rendered helpMessage.
htmlWrapperAttributes()
Returns string of HTML attributes for element wrapper paragraph.
htmlMarker()
Returns elements' required-indicator.
$type
Input element type - HTML input type attribute.
$helpMessage
Extra help message.
htmlValue()
Returns HTML-rendered element value.
$marker
Input element - HTML marker text that marks required fields.
getValue()
Returns the current input elements' value.
htmlErrorMessage()
Returns HTML-rendered error message.
htmlMax()
Renders HTML max attribute.
getStringValue()
getStringValue
typeCastValue()
Converts value to element specific type.
htmlMin()
Renders HTML min attribute.
$min
Minimum range HTML attribute.
__toString()
Renders element to HTML.
$step
Step HTML attribute.
validatorCall()
custom validator call
$max
Maximum range HTML attribute.
setDefaults()
collects initial values across subclasses.
htmlStep()
Renders HTML step attribute.
isEmpty()
custom empty check
htmlInputAttributes()
renders text element specific HTML attributes
htmlList($options=null)
Renders HTML datalist.