MDL-65069 core_form: Expose the form's submit's class attribute
authorPeter <peter@moodle.com>
Wed, 27 Mar 2019 07:21:24 +0000 (15:21 +0800)
committerPeter <peter@moodle.com>
Wed, 24 Apr 2019 02:29:30 +0000 (10:29 +0800)
Exposed the submit button's class attribute so it can be overriden by
custom classes provided by the programmer.

lib/form/submit.php
lib/form/templates/element-submit-inline.mustache
lib/form/templates/element-submit.mustache

index e40f457..23c1ff7 100644 (file)
@@ -48,6 +48,13 @@ class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatabl
      */
     protected $primary;
 
+    /**
+     * Any class apart from 'btn' would be override with this content
+     *
+     * @var string $customclassoverride Custom class override for the input element
+     */
+    protected $customclassoverride;
+
     /**
      * constructor
      *
@@ -65,6 +72,12 @@ class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatabl
         } else {
             $this->primary = $primary;
         }
+
+        $class = $this->getAttribute('customclassoverride');
+        if ($class) {
+            $this->removeAttribute('customclassoverride');
+            $this->customclassoverride = $class;
+        }
     }
 
     /**
@@ -131,6 +144,10 @@ class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatabl
         if (!$this->primary) {
             $context['secondary'] = true;
         }
+
+        if ($this->customclassoverride) {
+            $context['customclass'] = $this->customclassoverride;
+        }
         return $context;
     }
 }
index 7115850..d576e57 100644 (file)
@@ -3,9 +3,12 @@
         {{^element.frozen}}
         <input type="submit"
                 class="btn
-                    {{^element.secondary}}btn-primary{{/element.secondary}}
-                    {{#element.secondary}}btn-secondary{{/element.secondary}}
-                    {{#error}} btn-danger {{/error}}"
+                    {{^element.customclass}}
+                        {{^element.secondary}}btn-primary{{/element.secondary}}
+                        {{#element.secondary}}btn-secondary{{/element.secondary}}
+                    {{/element.customclass}}
+                    {{#error}} btn-danger {{/error}}
+                    {{#element.customclass}}{{element.customclass}}{{/element.customclass}}"
                 name="{{element.name}}"
                 id="{{element.id}}"
                 value="{{element.value}}"
index eca4f2b..5ca3e53 100644 (file)
@@ -3,9 +3,13 @@
         {{^element.frozen}}
             <input type="submit"
                 class="btn
-                    {{^element.secondary}}btn-primary{{/element.secondary}}
-                    {{#element.secondary}}btn-secondary{{/element.secondary}}
-                    {{#error}} btn-danger {{/error}}"
+                    {{^element.customclass}}
+                        {{^element.secondary}}btn-primary{{/element.secondary}}
+                        {{#element.secondary}}btn-secondary{{/element.secondary}}
+                    {{/element.customclass}}
+                    {{#error}} btn-danger {{/error}}
+                    {{element.extraclasses}}
+                    {{#element.customclass}}{{element.customclass}}{{/element.customclass}}"
                 name="{{element.name}}"
                 id="{{element.id}}"
                 {{#error}}