Afform - use search params instead of route params
authorColeman Watts <coleman@civicrm.org>
Tue, 2 Mar 2021 13:52:43 +0000 (08:52 -0500)
committerColeman Watts <coleman@civicrm.org>
Tue, 2 Mar 2021 19:09:51 +0000 (14:09 -0500)
ext/afform/core/ang/afCore.js

index 12836dde82147b02f52bd55713db240e8d88fb6b..cef661948e73a7b1d664794d3e93554771a7a7a9 100644 (file)
@@ -3,7 +3,7 @@
   angular.module('afCore', CRM.angRequires('afCore'));
 
   // Use `afCoreDirective(string name)` to generate an AngularJS directive.
-  angular.module('afCore').service('afCoreDirective', function($routeParams, crmApi4, crmStatus, crmUiAlert) {
+  angular.module('afCore').service('afCoreDirective', function($location, crmApi4, crmStatus, crmUiAlert) {
     return function(camelName, meta, d) {
       d.restrict = 'E';
       d.scope = {};
       d.link = {
         pre: function($scope, $el, $attr) {
           $scope.ts = CRM.ts(camelName);
-          $scope.routeParams = $routeParams;
           $scope.meta = meta;
           $scope.crmApi4 = crmApi4;
           $scope.crmStatus = crmStatus;
           $scope.crmUiAlert = crmUiAlert;
           $scope.crmUrl = CRM.url;
+
+          // Afforms do not use routing, but some forms get input from search params
+          $scope.$watch(function() {return $location.search();}, function(params) {
+            $scope.routeParams = params;
+          });
         }
       };
       return d;