MDL-68409 js: Add setButtonText modal helper
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 14 Apr 2020 00:54:57 +0000 (08:54 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Mon, 4 May 2020 07:07:48 +0000 (15:07 +0800)
lib/amd/build/modal.min.js
lib/amd/build/modal.min.js.map
lib/amd/build/modal_factory.min.js
lib/amd/build/modal_factory.min.js.map
lib/amd/src/modal.js
lib/amd/src/modal_factory.js

index 6825b53..dd36781 100644 (file)
Binary files a/lib/amd/build/modal.min.js and b/lib/amd/build/modal.min.js differ
index 49f3b81..f34fc87 100644 (file)
Binary files a/lib/amd/build/modal.min.js.map and b/lib/amd/build/modal.min.js.map differ
index 212386f..7f1a73f 100644 (file)
Binary files a/lib/amd/build/modal_factory.min.js and b/lib/amd/build/modal_factory.min.js differ
index 8116c26..93f24aa 100644 (file)
Binary files a/lib/amd/build/modal_factory.min.js.map and b/lib/amd/build/modal_factory.min.js.map differ
index 97d113a..279d4f7 100644 (file)
@@ -874,6 +874,25 @@ define([
         return p;
     };
 
         return p;
     };
 
+    /**
+     * Set the title text of a button.
+     *
+     * This method is overloaded to take either a string value for the button title or a jQuery promise that is resolved with
+     * text most commonly from a Str.get_string call.
+     *
+     * @param {DOMString} action The action of the button
+     * @param {(String|object)} value The button text, or a promise which will resolve to it
+     * @returns {Promise}
+     */
+    Modal.prototype.setButtonText = function(action, value) {
+        const button = this.getFooter().find(this.getActionSelector(action));
+
+        if (!button) {
+            throw new Error("Unable to find the '" + action + "' button");
+        }
+
+        return this.asyncSet(value, button.text.bind(button));
+    };
 
     /**
      * Get the Selector for an action.
 
     /**
      * Get the Selector for an action.
index 65c8854..a7d070d 100644 (file)
@@ -185,6 +185,12 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal',
                     modal.setFooter(modalConfig.footer);
                 }
 
                     modal.setFooter(modalConfig.footer);
                 }
 
+                if (modalConfig.buttons) {
+                    Object.entries(modalConfig.buttons).forEach(function([key, value]) {
+                        modal.setButtonText(key, value);
+                    });
+                }
+
                 if (isLarge) {
                     modal.setLarge();
                 }
                 if (isLarge) {
                     modal.setLarge();
                 }