afform - Get default field `<label>` from `label` instead of `title`
authorTim Otten <totten@civicrm.org>
Wed, 18 Nov 2020 01:29:56 +0000 (17:29 -0800)
committerTim Otten <totten@civicrm.org>
Wed, 18 Nov 2020 19:36:50 +0000 (11:36 -0800)
ext/afform/auditor/backlog.md
ext/afform/core/afform.php
ext/afform/core/ang/af/afField.html
ext/afform/core/tests/phpunit/Civi/Afform/FilterTest.php
ext/afform/gui/afform_gui.php
ext/afform/gui/ang/afGuiEditor.js
ext/afform/gui/ang/afGuiEditor/entity.html
ext/afform/gui/ang/afGuiEditor/field.html

index c5230b4150e9b48a2c1dfedff1bbe0b30fd07ae8..5ea347bd03cce42414ae562f441106a6bacc19d2 100644 (file)
@@ -10,6 +10,7 @@ validator to catch. Loosely/informally:
 * `<af-form>`, `<af-entity>`, `<af-fieldset>`, `<af-field>` should have suitable relationships.
 * `<af-entity>` should reference legit entities.
 * `<af-field>` should reference legit fields.
+    * The optional override `defn='{label:...}` changed to `defn={title:...}`
     * Future consideration: how to validate when it's part of a subform?
 * `<af-fieldset>` should reference a declared model.
 * `<af-field defn="...">` should contain an object.
index c78170823b88598d0f8c1bf6e6d22be1ed40ffdc..e9bceafed789e30e739a5b998f2be86d3ea4db84 100644 (file)
@@ -351,7 +351,7 @@ function _af_fill_field_metadata($entityType, DOMElement $afField) {
   $params = [
     'action' => 'create',
     'where' => [['name', '=', $afField->getAttribute('name')]],
-    'select' => ['title', 'input_type', 'input_attrs', 'options'],
+    'select' => ['label', 'input_type', 'input_attrs', 'options'],
     'loadOptions' => TRUE,
   ];
   if (in_array($entityType, CRM_Contact_BAO_ContactType::basicTypes(TRUE))) {
index 709a7cbefba61964784cfa81223e11ed9cfe8a61..6fb2f55f859cc82a09e6700537da1bc18ae2292d 100644 (file)
@@ -1,5 +1,5 @@
-<label class="crm-af-field-label" ng-if="defn.title" for="{{ fieldId }}">
-  {{ defn.title }}
+<label class="crm-af-field-label" ng-if="defn.label" for="{{ fieldId }}">
+  {{ defn.label }}
 </label>
 <p class="crm-af-field-help-pre" ng-if="defn.help_pre">{{ defn.help_pre }}</p>
 <div class="crm-af-field" ng-include="'~/af/fields/' + defn.input_type + '.html'"></div>
index fba7e5e028b352a71e1977334ef70e3574e86bcf..4e84b5592d37c7c197bba8aab2d1b235ffc2d6ae 100644 (file)
@@ -43,7 +43,7 @@ class FilterTest extends \PHPUnit\Framework\TestCase implements HeadlessInterfac
 
     $myField = $parsed[0]['#children'][1]['#children'][0];
     $this->assertEquals('af-field', $myField['#tag']);
-    $this->assertEquals('First Name', $myField['defn']['title']);
+    $this->assertEquals('First Name', $myField['defn']['label']);
   }
 
   public function testDefnInjectionNested() {
@@ -55,19 +55,19 @@ class FilterTest extends \PHPUnit\Framework\TestCase implements HeadlessInterfac
 
     $myField = $parsed[0]['#children'][1]['#children'][0]['#children'][0]['#children'][0];
     $this->assertEquals('af-field', $myField['#tag']);
-    $this->assertEquals('First Name', $myField['defn']['title']);
+    $this->assertEquals('First Name', $myField['defn']['label']);
   }
 
   public function testDefnOverrideTitle() {
     $inputHtml = sprintf(self::PERSON_TPL,
-      '<div af-fieldset="person"><af-field name="first_name" defn="{title: \'Given name\'}" /></div>');
+      '<div af-fieldset="person"><af-field name="first_name" defn="{label: \'Given name\'}" /></div>');
     $filteredHtml = $this->htmlFilter('~/afform/MyForm.aff.html', $inputHtml);
     $converter = new \CRM_Afform_ArrayHtml(TRUE);
     $parsed = $converter->convertHtmlToArray($filteredHtml);
 
     $myField = $parsed[0]['#children'][1]['#children'][0];
     $this->assertEquals('af-field', $myField['#tag']);
-    $this->assertEquals('Given name', $myField['defn']['title']);
+    $this->assertEquals('Given name', $myField['defn']['label']);
     $this->assertEquals('Text', $myField['defn']['input_type']);
   }
 
index c5fe4e3091257d7249aa16fe0c8b9cd537c3bf26..4a10bf342b4afd7ebf9dc502858d2c81162671de 100644 (file)
@@ -167,7 +167,7 @@ function afform_gui_civicrm_buildAsset($asset, $params, &$mimeType, &$content) {
     'includeCustom' => TRUE,
     'loadOptions' => TRUE,
     'action' => 'create',
-    'select' => ['name', 'title', 'input_type', 'input_attrs', 'required', 'options', 'help_pre', 'help_post', 'serialize', 'data_type'],
+    'select' => ['name', 'label', 'input_type', 'input_attrs', 'required', 'options', 'help_pre', 'help_post', 'serialize', 'data_type'],
     'where' => [['input_type', 'IS NOT NULL']],
   ];
 
index d0c760f4f8e256d2f9cf08985898a8766ff6dc3e..a0cf7992a592d84914e6f0ae585f625b2d79208a 100644 (file)
 
         $scope.valuesFields = function() {
           var fields = _.transform($scope.getMeta().fields, function(fields, field) {
-            fields.push({id: field.name, text: field.title, disabled: $scope.fieldInUse(field.name)});
+            fields.push({id: field.name, text: field.label, disabled: $scope.fieldInUse(field.name)});
           }, []);
           return {results: fields};
         };
 
           function filterFields(fields) {
             return _.transform(fields, function(fieldList, field) {
-              if (!search || _.contains(field.name, search) || _.contains(field.title.toLowerCase(), search)) {
+              if (!search || _.contains(field.name, search) || _.contains(field.label.toLowerCase(), search)) {
                 fieldList.push({
                   "#tag": "af-field",
                   name: field.name
 
         $scope.toggleLabel = function() {
           $scope.node.defn = $scope.node.defn || {};
-          if ($scope.node.defn.title === false) {
-            delete $scope.node.defn.title;
+          if ($scope.node.defn.label === false) {
+            delete $scope.node.defn.label;
           } else {
-            $scope.node.defn.title = false;
+            $scope.node.defn.label = false;
           }
         };
 
index f709cff6bdc362da23c5eb5dbd6dc259fb3831b9..150f5e7ba4cbd0c159b02fa2bfe23d421af5ced9 100644 (file)
@@ -2,7 +2,7 @@
   <fieldset class="af-gui-entity-values">
     <legend>{{ ts('Values:') }}</legend>
     <div class="form-inline" ng-if="getMeta().fields[fieldName]" ng-repeat="(fieldName, value) in entity.data">
-      <label>{{ getMeta().fields[fieldName].title }}:</label><br />
+      <label>{{ getMeta().fields[fieldName].label }}:</label><br />
       <input class="form-control" af-gui-field-value="editor.getField(entity.type, fieldName)" ng-model="entity.data[fieldName]" />
       <a href ng-click="removeValue(entity, fieldName)">
         <i class="crm-i fa-times"></i>
@@ -41,7 +41,7 @@
           <label>{{ fieldGroup.label }}</label>
           <div ui-sortable="{update: buildPaletteLists, items: '&gt; div:not(.disabled)', connectWith: '[data-entity=' + fieldGroup.entityName + '] &gt; [ui-sortable]', placeholder: 'af-gui-dropzone'}" ui-sortable-update="editor.onDrop" ng-model="fieldGroup.fields">
             <div ng-repeat="field in fieldGroup.fields" ng-class="{disabled: fieldInUse(field.name)}">
-              {{ editor.getField(fieldGroup.entityType, field.name).title }}
+              {{ editor.getField(fieldGroup.entityType, field.name).label }}
             </div>
           </div>
         </div>
index 04f9c97eccc0590824a52fc267ab2a37aa8fdf9b..4b5ce5f08ae9f712a64d16d956992c407b645da5 100644 (file)
@@ -1,6 +1,6 @@
 <div af-gui-edit-options ng-if="editingOptions" class="af-gui-content-editing-area"></div>
 <div ng-if="!editingOptions" class="af-gui-element af-gui-field" >
-  <div class="af-gui-bar" title="{{ getEntity().label + ': ' + getDefn().title }}">
+  <div class="af-gui-bar" title="{{ getEntity().label + ': ' + getDefn().label }}">
     <div class="form-inline pull-right">
       <div class="btn-group" af-gui-menu >
         <button type="button" class="btn btn-default btn-xs dropdown-toggle af-gui-add-element-button" data-toggle="dropdown" title="{{ ts('Configure') }}">
@@ -10,8 +10,8 @@
       </div>
     </div>
   </div>
-  <label ng-style="{visibility: node.defn.title === false ? 'hidden' : 'visible'}" ng-class="{'af-gui-field-required': getProp('required')}" class="af-gui-node-title">
-    <span af-gui-editable ng-model="getSet('title')" ng-model-options="{getterSetter: true}" default-value="getDefn().title">{{ getProp('title') }}</span>
+  <label ng-style="{visibility: node.defn.label === false ? 'hidden' : 'visible'}" ng-class="{'af-gui-field-required': getProp('required')}" class="af-gui-node-title">
+    <span af-gui-editable ng-model="getSet('label')" ng-model-options="{getterSetter: true}" default-value="getDefn().label">{{ getProp('label') }}</span>
   </label>
   <div class="af-gui-field-help" ng-if="propIsset('help_pre')">
     <span af-gui-editable ng-model="getSet('help_pre')" ng-model-options="{getterSetter: true}" default-value="getDefn().help_pre">{{ getProp('help_pre') }}</span>