MediaWiki
master
Toggle main menu visibility
HTMLFloatField.php
Go to the documentation of this file.
1
<?php
2
3
namespace
MediaWiki\HTMLForm\Field;
4
10
class
HTMLFloatField
extends
HTMLTextField
{
12
public
function
getSize
() {
13
return
$this->mParams[
'size'
] ?? 20;
14
}
15
17
public
function
validate
( $value, $alldata ) {
18
$p = parent::validate( $value, $alldata );
19
20
if
( $p !==
true
) {
21
return
$p;
22
}
23
24
$value = trim( $value ??
''
);
25
if
( $value ===
''
) {
26
return
true
;
27
}
28
29
# https:
//www.w3.org/TR/html5/infrastructure.html#floating-point-numbers
30
# with the addition that a leading '+' sign is ok.
31
if
( !preg_match(
'/^((\+|\-)?\d+(\.\d+)?(E(\+|\-)?\d+)?)?$/i'
, $value ) ) {
32
return
$this->
msg
(
'htmlform-float-invalid'
);
33
}
34
35
# The "int" part of these message names is rather confusing.
36
# They make equal sense for all numbers.
37
if
( isset( $this->mParams[
'min'
] ) ) {
38
$min = $this->mParams[
'min'
];
39
40
if
( $min > $value ) {
41
return
$this->
msg
(
'htmlform-int-toolow'
, $min );
42
}
43
}
44
45
if
( isset( $this->mParams[
'max'
] ) ) {
46
$max = $this->mParams[
'max'
];
47
48
if
( $max < $value ) {
49
return
$this->
msg
(
'htmlform-int-toohigh'
, $max );
50
}
51
}
52
53
return
true
;
54
}
55
60
protected
function
getInputWidget
( $params ) {
61
return
new \OOUI\NumberInputWidget( $params );
62
}
63
}
64
66
class_alias( HTMLFloatField::class,
'HTMLFloatField'
);
MediaWiki\HTMLForm\Field\HTMLFloatField
A field that will contain a numeric value.
Definition
HTMLFloatField.php:10
MediaWiki\HTMLForm\Field\HTMLFloatField\validate
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.Don't forget to call pare...
Definition
HTMLFloatField.php:17
MediaWiki\HTMLForm\Field\HTMLFloatField\getInputWidget
getInputWidget( $params)
to overrideWidget
Definition
HTMLFloatField.php:60
MediaWiki\HTMLForm\Field\HTMLFloatField\getSize
getSize()
to override int
Definition
HTMLFloatField.php:12
MediaWiki\HTMLForm\Field\HTMLTextField
<input> field.
Definition
HTMLTextField.php:23
MediaWiki\HTMLForm\HTMLFormField\msg
msg( $key,... $params)
Get a translated interface message.
Definition
HTMLFormField.php:138
includes
HTMLForm
Field
HTMLFloatField.php
Generated on
for MediaWiki by
1.18.0