Afform Gui - Basic validation & defaults for server_route
authorColeman Watts <coleman@civicrm.org>
Mon, 1 Feb 2021 22:46:26 +0000 (17:46 -0500)
committerColeman Watts <coleman@civicrm.org>
Tue, 2 Feb 2021 15:12:04 +0000 (10:12 -0500)
ext/afform/admin/CRM/AfformAdmin/Upgrader.php
ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js
ext/afform/admin/ang/afGuiEditor/config-form.html

index 5a402f727a49f4747410da1d84279b7e76254598..616e6305cc86059955e23a54977cdeb52d6ad42a 100644 (file)
@@ -29,7 +29,7 @@ class CRM_AfformAdmin_Upgrader extends CRM_AfformAdmin_Upgrader_Base {
           'permission' => 'administer CiviCRM',
           'url' => 'civicrm/admin/afform',
           'is_active' => 1,
-          'icon' => 'crm-i fa-list-alt'
+          'icon' => 'crm-i fa-list-alt',
         ]);
       }
     }
@@ -55,15 +55,15 @@ class CRM_AfformAdmin_Upgrader extends CRM_AfformAdmin_Upgrader_Base {
    * @return TRUE on success
    * @throws Exception
    */
-   public function upgrade_0001() {
-     $this->ctx->log->info('Applying update 0001');
-     \Civi\Api4\Navigation::update(FALSE)
-       ->addValue('icon', 'crm-i fa-list-alt')
-       ->addValue('label', E::ts('Form Builder'))
-       ->addValue('name', 'afform_admin')
-       ->addWhere('name', '=', 'afform_gui')
-       ->execute();
-     return TRUE;
-   }
+  public function upgrade_0001() {
+    $this->ctx->log->info('Applying update 0001');
+    \Civi\Api4\Navigation::update(FALSE)
+      ->addValue('icon', 'crm-i fa-list-alt')
+      ->addValue('label', E::ts('Form Builder'))
+      ->addValue('name', 'afform_admin')
+      ->addWhere('name', '=', 'afform_gui')
+      ->execute();
+    return TRUE;
+  }
 
 }
index 288a4bb503e6dcbca6508315759015b68ceb29f8..d617cad64930529ecb7f20365cfd68715c7f3a2a 100644 (file)
       };
 
       $scope.save = function() {
+        var afform = JSON.parse(angular.toJson($scope.afform));
+        // This might be set to undefined by validation
+        afform.server_route = afform.server_route || '';
         $scope.saving = $scope.changesSaved = true;
-        crmApi4('Afform', 'save', {formatWhitespace: true, records: [JSON.parse(angular.toJson($scope.afform))]})
+        crmApi4('Afform', 'save', {formatWhitespace: true, records: [afform]})
           .then(function (data) {
             $scope.saving = false;
             $scope.afform.name = data[0].name;
index 58630edfa58d7569817db263b8f9385f93c9499d..1a3ac253c8cd5690637c493ce50621279515d207 100644 (file)
@@ -4,7 +4,7 @@
   <label for="af_config_form_title">
     {{:: ts('Title:') }} <span class="crm-marker">*</span>
   </label>
-  <input ng-model="afform.title" class="form-control" id="af_config_form_title" required />
+  <input ng-model="afform.title" class="form-control" id="af_config_form_title" required title="{{:: ts('Required') }}" />
 </div>
 
 <div class="form-group">
 
 <div class="form-group">
   <label for="af_config_form_server_route">
-    {{:: ts('Path:') }}
+    {{:: ts('Page:') }}
   </label>
-  <input ng-model="afform.server_route" class="form-control" id="af_config_form_server_route" />
-  <p class="help-block">{{:: ts('Expose the form as a standalone page on the web site. (Example: "civicrm/my-form")') }}</p>
+  <input ng-model="afform.server_route" class="form-control" id="af_config_form_server_route" pattern="^civicrm\/[-0-9a-zA-z\/_]+$" onfocus="this.value = this.value || 'civicrm/'" onblur="if (this.value === 'civicrm/') this.value = ''" title="{{:: ts('Path must begin with &quot;civicrm/&quot;') }}">
+  <p class="help-block">{{:: ts('Expose the form as a standalone webpage. (Must begin with "civicrm/" e.g. "civicrm/my-form")') }}</p>
 </div>
 
 <div class="form-group" ng-if="!!afform.server_route">