HTMLForms: Support non submit buttons
authorMatt Walker <mwalker@wikimedia.org>
Thu, 21 Mar 2013 00:54:32 +0000 (17:54 -0700)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 23 Apr 2013 06:52:52 +0000 (06:52 +0000)
There is now a new generic HTMLButtonField class which does
not need to be a submit button.

Change-Id: I451a952bba0c7339b5337e5201417beaee3f16fd

includes/HTMLForm.php

index b7bdcfd..2d0cefc 100644 (file)
@@ -2542,7 +2542,19 @@ class HTMLHiddenField extends HTMLFormField {
  * Add a submit button inline in the form (as opposed to
  * HTMLForm::addButton(), which will add it at the end).
  */
-class HTMLSubmitField extends HTMLFormField {
+class HTMLSubmitField extends HTMLButtonField {
+       protected $buttonType = 'submit';
+}
+
+/**
+ * Adds a generic button inline to the form. Does not do anything, you must add
+ * click handling code in JavaScript. Use a HTMLSubmitField if you merely
+ * wish to add a submit button to a form.
+ *
+ * @since 1.22
+ */
+class HTMLButtonField extends HTMLFormField {
+       protected $buttonType = 'button';
 
        public function __construct( $info ) {
                $info['nodata'] = true;
@@ -2552,7 +2564,6 @@ class HTMLSubmitField extends HTMLFormField {
        public function getInputHTML( $value ) {
                $attr = array(
                        'class' => 'mw-htmlform-submit ' . $this->mClass,
-                       'name' => $this->mName,
                        'id' => $this->mID,
                );
 
@@ -2560,7 +2571,12 @@ class HTMLSubmitField extends HTMLFormField {
                        $attr['disabled'] = 'disabled';
                }
 
-               return Xml::submitButton( $value, $attr );
+               return Html::input(
+                       $this->mName,
+                       $value,
+                       $this->buttonType,
+                       $attr
+               );
        }
 
        protected function needsLabel() {