af/Form.js - Get the form name implicitly (without a global)
authorTim Otten <totten@civicrm.org>
Sat, 14 Sep 2019 00:57:39 +0000 (20:57 -0400)
committerCiviCRM <info@civicrm.org>
Wed, 16 Sep 2020 02:13:19 +0000 (19:13 -0700)
ext/afform/core/CRM/Afform/Page/AfformBase.php
ext/afform/core/ang/af/Form.js

index 8684e0431536baf7acbb3c58e6cd4aab25d65827..3d389528b605092d1f3961d6682536952c11ebfe 100644 (file)
@@ -13,7 +13,6 @@ class CRM_Afform_Page_AfformBase extends CRM_Core_Page {
     $loader->setPageName(implode('/', $pagePath));
     $loader->getRes()->addSetting([
       'afform' => [
-        'name' => $pageArgs['afform'],
         'open' => _afform_angular_module_name($pageArgs['afform'], 'dash'),
       ],
     ]);
index 304ea43e0e2d21c5f5a404863ac5a761c0d03e60..c5098391e6c894ab1a262c181de53c0c0e3ef493 100644 (file)
         this.getSchema = function getSchema(name) {
           return schema[name];
         };
+        // Returns the 'meta' record ('name', 'description', etc) of the active form.
+        this.getFormMeta = function getFormMeta() {
+          return $scope.$parent.meta;
+        };
         this.loadData = function() {
           var toLoad = 0;
           _.each(schema, function(entity, entityName) {
@@ -45,7 +49,7 @@
             }
           });
           if (toLoad) {
-            crmApi4('Afform', 'prefill', {name: CRM.afform.name, args: $routeParams})
+            crmApi4('Afform', 'prefill', {name: this.getFormMeta().name, args: $routeParams})
               .then(function(result) {
                 _.each(result, function(item) {
                   data[item.name] = _.extend(item.values, schema[item.name].data || {});
@@ -55,7 +59,7 @@
         };
 
         this.submit = function submit() {
-          crmApi4('Afform', 'submit', {name: CRM.afform.name, args: $routeParams, values: data});
+          crmApi4('Afform', 'submit', {name: this.getFormMeta().name, args: $routeParams, values: data});
         };
       }
     };