3 namespace MediaWiki\HTMLForm\Field
;
6 * A field that will contain a numeric value
10 class HTMLFloatField
extends HTMLTextField
{
11 public function getSize() {
12 return $this->mParams
['size'] ??
20;
15 public function validate( $value, $alldata ) {
16 $p = parent
::validate( $value, $alldata );
22 $value = trim( $value ??
'' );
24 # https://www.w3.org/TR/html5/infrastructure.html#floating-point-numbers
25 # with the addition that a leading '+' sign is ok.
26 if ( !preg_match( '/^((\+|\-)?\d+(\.\d+)?(E(\+|\-)?\d+)?)?$/i', $value ) ) {
27 return $this->msg( 'htmlform-float-invalid' );
30 # The "int" part of these message names is rather confusing.
31 # They make equal sense for all numbers.
32 if ( isset( $this->mParams
['min'] ) ) {
33 $min = $this->mParams
['min'];
35 if ( $min > $value ) {
36 return $this->msg( 'htmlform-int-toolow', $min );
40 if ( isset( $this->mParams
['max'] ) ) {
41 $max = $this->mParams
['max'];
43 if ( $max < $value ) {
44 return $this->msg( 'htmlform-int-toohigh', $max );
55 protected function getInputWidget( $params ) {
56 return new \OOUI\
NumberInputWidget( $params );
60 /** @deprecated class alias since 1.42 */
61 class_alias( HTMLFloatField
::class, 'HTMLFloatField' );