Add mock testAfform
authorColeman Watts <coleman@civicrm.org>
Sat, 14 Sep 2019 00:03:35 +0000 (20:03 -0400)
committerCiviCRM <info@civicrm.org>
Wed, 16 Sep 2020 02:13:19 +0000 (19:13 -0700)
ext/afform/core/afform.php
ext/afform/mock/ang/testAfform.aff.html [new file with mode: 0644]
ext/afform/mock/ang/testAfform.aff.json [new file with mode: 0644]

index 6eb602bc1fded9c135cf79580a3b627ab82c6ee8..9ea9da18f69c6def3763fb33d29d968c60512a47 100644 (file)
@@ -182,7 +182,7 @@ function afform_civicrm_alterAngular($angular) {
       foreach (pq('af-field', $doc) as $afField) {
         /** @var DOMElement $afField */
         $fieldName = $afField->getAttribute('name');
-        $entityName = pq($afField)->parent('af-fieldset[model]')->attr('model'); // TEST ME
+        $entityName = pq($afField)->parent('af-fieldset[model]')->attr('model');
         if (!preg_match(';^[a-zA-Z0-9\_\-\. ]+$;', $entityName)) {
           throw new \CRM_Core_Exception("Cannot process $path: malformed entity name ($entityName)");
         }
diff --git a/ext/afform/mock/ang/testAfform.aff.html b/ext/afform/mock/ang/testAfform.aff.html
new file mode 100644 (file)
index 0000000..add785c
--- /dev/null
@@ -0,0 +1,27 @@
+<af-form ctrl="modelListCtrl" >
+  <div crm-ui-debug="modelListCtrl.getEntity('parent')" />
+  <div crm-ui-debug="modelListCtrl.getData('parent')" />
+  <af-model type="Contact" data="{contact_type: 'Individual'}" name="parent" label="Parent" url-autofill="1" autofill="user" />
+  <af-model type="Contact" name="spouse" label="Spouse" url-autofill="1" />
+  <af-model type="Contact" name="home" label="Home" />
+
+  <af-fieldset model="parent">
+
+    <af-field name="first_name" defn='{title: ts("Your First Name")}' />
+    <af-field name="last_name" />
+    <af-field name="contact_sub_type" defn="{widget: hidden}" value="Student" />
+    <af-field name="gender_id" />
+    <af-field name="constituent_information.Marital_Status" />
+    <af-field name="constituent_information.Marriage_Date" />
+    <af-field name="constituent_information.Most_Important_Issue" />
+  </af-fieldset>
+
+  <af-fieldset model="spouse">
+    <af-field name="first_name" defn='{title: ts("Spouse First Name")}' />
+    <af-field name="last_name" />
+  </af-fieldset>
+
+  <!-- General elements: FIELDSET, UL, BUTTON, P, H1 should work anywhere -->
+  <button ng-click="modelListCtrl.submit()">Submit</button>
+
+</af-form>
diff --git a/ext/afform/mock/ang/testAfform.aff.json b/ext/afform/mock/ang/testAfform.aff.json
new file mode 100644 (file)
index 0000000..5fc368c
--- /dev/null
@@ -0,0 +1,7 @@
+{
+  "server_route": "civicrm/test-afform",
+  "title": "This is a test",
+  "requires": [
+    "af", "afBlock", "afField", "afCore"
+  ]
+}