MediaWiki
1.34.0
HTMLFloatField.php
Go to the documentation of this file.
1
<?php
2
6
class
HTMLFloatField
extends
HTMLTextField
{
7
public
function
getSize
() {
8
return
$this->mParams[
'size'
] ?? 20;
9
}
10
11
public
function
validate
( $value, $alldata ) {
12
$p = parent::validate( $value, $alldata );
13
14
if
( $p !==
true
) {
15
return
$p;
16
}
17
18
$value = trim( $value );
19
20
# https://www.w3.org/TR/html5/infrastructure.html#floating-point-numbers
21
# with the addition that a leading '+' sign is ok.
22
if
( !preg_match(
'/^((\+|\-)?\d+(\.\d+)?(E(\+|\-)?\d+)?)?$/i'
, $value ) ) {
23
return
$this->
msg
(
'htmlform-float-invalid'
);
24
}
25
26
# The "int" part of these message names is rather confusing.
27
# They make equal sense for all numbers.
28
if
( isset( $this->mParams[
'min'
] ) ) {
29
$min = $this->mParams[
'min'
];
30
31
if
( $min > $value ) {
32
return
$this->
msg
(
'htmlform-int-toolow'
, $min );
33
}
34
}
35
36
if
( isset( $this->mParams[
'max'
] ) ) {
37
$max = $this->mParams[
'max'
];
38
39
if
( $max < $value ) {
40
return
$this->
msg
(
'htmlform-int-toohigh'
, $max );
41
}
42
}
43
44
return
true
;
45
}
46
47
protected
function
getInputWidget
( $params ) {
48
return
new
OOUI\NumberInputWidget( $params );
49
}
50
}
HTMLFloatField
A field that will contain a numeric value.
Definition:
HTMLFloatField.php:6
HTMLTextField
<input> field.
Definition:
HTMLTextField.php:11
HTMLFloatField\validate
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
Definition:
HTMLFloatField.php:11
HTMLFloatField\getSize
getSize()
Definition:
HTMLFloatField.php:7
HTMLFormField\msg
msg( $key,... $params)
Get a translated interface message.
Definition:
HTMLFormField.php:83
HTMLFloatField\getInputWidget
getInputWidget( $params)
Definition:
HTMLFloatField.php:47
includes
htmlform
fields
HTMLFloatField.php
Generated on Thu Dec 19 2019 14:54:21 for MediaWiki by
1.8.16