MDL-69166 core-payment: Autoselect gateway when there is only one
authorShamim Rezaie <shamim@moodle.com>
Tue, 29 Sep 2020 11:32:13 +0000 (21:32 +1000)
committerShamim Rezaie <shamim@moodle.com>
Tue, 27 Oct 2020 03:40:49 +0000 (14:40 +1100)
payment/amd/build/gateways_modal.min.js
payment/amd/build/gateways_modal.min.js.map
payment/amd/src/gateways_modal.js

index 963edab..e9eb400 100644 (file)
Binary files a/payment/amd/build/gateways_modal.min.js and b/payment/amd/build/gateways_modal.min.js differ
index 2b632d4..ac71fb7 100644 (file)
Binary files a/payment/amd/build/gateways_modal.min.js.map and b/payment/amd/build/gateways_modal.min.js.map differ
index a115e71..4160677 100644 (file)
@@ -140,9 +140,23 @@ const show = async(rootNode, {
 
     const {html, js} = await Templates.renderForPromise('core_payment/gateways', context);
     Templates.replaceNodeContents(rootElement.querySelector(Selectors.regions.gatewaysContainer), html, js);
+    selectSingleGateway(rootElement);
     await updateCostRegion(rootElement, parseFloat(rootNode.dataset.amount), rootNode.dataset.currency);
 };
 
+/**
+ * Auto-select the gateway if there is only one gateway.
+ *
+ * @param {HTMLElement} root An HTMLElement that contains the cost region
+ */
+const selectSingleGateway = root => {
+    const gateways = root.querySelectorAll(Selectors.elements.gateways);
+
+    if (gateways.length == 1) {
+        gateways[0].checked = true;
+    }
+};
+
 /**
  * Shows the cost of the item the user is purchasing in the cost region.
  *