瀏覽代碼

Syncing with version in lmp-client

Richard Knight 6 年之前
父節點
當前提交
2c228d3bca

+ 2 - 0
src/app/dynaform/components/_abstract/group-input.component.ts

@@ -18,6 +18,8 @@ export abstract class GroupInputComponent implements OnInit {
 	ngOnInit() {
 		// Move meta variables up a level, for direct access in templates
 		this.exposeMetaInTemplate.map(p => this[p] = this.meta[p] !== undefined ? this.meta[p] : this[p]);
+		
+		// Get the FormGroup, and information about the controls inside it
 		this.formGroup = this.control as FormGroup;
 		this.childMetaArray = Object.values(this.meta.meta); // Metadata array of all controls in group
 		this.controlNames = Object.keys(this.formGroup.controls);

+ 1 - 1
src/app/dynaform/directives/dynafield.directive.ts

@@ -12,7 +12,7 @@ import {
 import * as formFieldComponents from './../components';
 
 interface FFC {
-	control: FormControl; // Remember, this can be an individual control or a FormGroup
+	control: FormControl; // Remember, this can be an individual FormControl or a FormGroup
 	meta: StringMap;
 	propagateChange?: Function;
 	call?: EventEmitter<string>

+ 2 - 2
src/app/dynaform/models/field.model.ts

@@ -1,8 +1,8 @@
-/* **********************************************************************************************************************
+/* *********************************************************************************************************************
  * MetaData models for Form Fields
  * -------------------------------
  * Keep in one file for now, but maybe split if this grows too large
- ********************************************************************************************************************* */
+ ******************************************************************************************************************** */
 
 import { TemplateRef } from '@angular/core'; 
 import { ValidatorFn, AsyncValidatorFn } from '@angular/forms';

+ 4 - 3
src/app/dynaform/services/_formdata-utils.ts

@@ -108,11 +108,12 @@ const buildFieldSpecificMeta = metaG => _buildFieldSpecificMeta(addMissingNames(
 
 
 // ---------------------------------------------------------------------------------------------------------------------
-// Build FormGroups
+// Build Form Group Function Factory
+// returns a function to build FormGroups containing FormControls, FormArrays and other FormGroups
 // ---------------------------------------------------------------------------------------------------------------------
 
 const buildFormGroupFunctionFactory = (fb: FormBuilder): (meta) => FormGroup => {
-	// Establishes a closre over the supplied FormBuilder and returns a function that builds FormGroups from metadata
+	// Establishes a closure over the supplied FormBuilder and returns a function that builds FormGroups from metadata
 	// ( it's done this way so we can use the FormBuilder singleton without reinitialising )
 
 	// Build Form Control
@@ -151,7 +152,7 @@ const buildFormGroupFunctionFactory = (fb: FormBuilder): (meta) => FormGroup =>
 // Helper Functions
 // ---------------------------------------------------------------------------------------------------------------------
 
-// Add Property to object
+// Add Property to object, returning updated object
 const addProp = (obj, key, val) => { obj[key] = val; return obj; };
 
 // Is Group

+ 26 - 6
src/app/dynaform/services/dynaform.service.ts

@@ -1,7 +1,11 @@
-/* ***************************************************************************************************************************************
- * Dynaform Service, exposing 8 public methods
- * ***************************************************************************************************************************************
- *
+/* *********************************************************************************************************************
+ * Dynaform Service, exposing 10 public methods
+ * *********************************************************************************************************************
+ * 
+ * BUILD
+ * -----
+ * This is the main method you'll use to build forms from models and metadata:
+ * 
  * build(model, meta = {}, createFromMeta = false)
  *
  * Takes a model and (lazy)metadata and returns an object containing a FormGroup and Modeled MetaData :
@@ -18,7 +22,7 @@
  * but exist in the metadata. This is NOT the default behaviour, except when an empty model is supplied.
  * i.e. It defaults to false, except when model == {}
  *
- * USAGE
+ * Usage
  * -----
  *
  * build(model)				- build everything from the model
@@ -27,6 +31,20 @@
  * build(model, meta, true)	- build by combining model with metadata, creating new fields from metadata points that don't occur in the model
  *
  *
+ * REGISTER
+ * --------
+ * Registers callbacks attached to the form (e.g. to buttons), identified by strings.
+ * 
+ * register({ 
+ *             'SAYHELLO': () => { alert('HELLO') },
+ *             'SEARCH': execSearch,
+ *             'NEW': addNew,
+ *          }, varToBind);
+ *
+ * If varToBind is supplied it is bound as 'this' to the functions.
+ * Typically you'd supply the component class instance, so that 'this' used in callbacks refers to the host component.
+ * 
+ * 
  * LOWER-LEVEL METHODS
  * -------------------
  *
@@ -86,7 +104,9 @@ export class DynaformService {
 
 	register(callbacks: Callbacks, cref: ComponentRef<any>['instance']) {
 		// Bind the component instance to the callback, so that 'this' has the context of the component
-		Object.entries(callbacks).forEach(([key, fn]) => this.callbacks[key] = fn.bind(cref));
+		if (cref) {
+			Object.entries(callbacks).forEach(([key, fn]) => this.callbacks[key] = fn.bind(cref));
+		}
 	}
 	
 	call(fnId: string) {