|
@@ -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) {
|