Use NumberInputWidget in HTMLFloatField
authormainframe98 <k.s.werf@hotmail.com>
Thu, 6 Sep 2018 12:21:46 +0000 (14:21 +0200)
committerMainframe98 <k.s.werf@hotmail.com>
Wed, 12 Sep 2018 08:12:42 +0000 (08:12 +0000)
The PHP variant of this widget was introduced in 0.27.0.
Using NumberInputWidget has the advantage that HTMLFloatField and
HTMLIntField can now be infused as a JavaScript NumberInputWidget.

Bug: T203656
Change-Id: I5d6a913de38d12a21c9bfb1ce9790574d98a5a1b

includes/htmlform/fields/HTMLFloatField.php
includes/htmlform/fields/HTMLTextField.php

index 72381f0..15426fd 100644 (file)
@@ -43,4 +43,8 @@ class HTMLFloatField extends HTMLTextField {
 
                return true;
        }
+
+       protected function getInputWidget( $params ) {
+               return new OOUI\NumberInputWidget( $params );
+       }
 }
index b51182a..d988c29 100644 (file)
@@ -117,6 +117,7 @@ class HTMLTextField extends HTMLFormField {
                        switch ( $this->mParams['type'] ) {
                                case 'int':
                                        $type = 'number';
+                                       $attribs['step'] = 1;
                                        break;
                                case 'float':
                                        $type = 'number';
@@ -181,6 +182,9 @@ class HTMLTextField extends HTMLFormField {
                }
 
                $type = $this->getType( $attribs );
+               if ( isset( $attribs['step'] ) && $attribs['step'] === 'any' ) {
+                       $attribs['step'] = null;
+               }
 
                return $this->getInputWidget( [
                        'id' => $this->mID,