@ng-modular-forms/core 0.7.8 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -138,22 +138,23 @@ Encapsulates cross-field reactive behavior. Keeps UI logic out of the component.
138
138
 
139
139
  ```ts
140
140
  import { Subscription } from 'rxjs';
141
- import { FormHandlerBase, getControl } from '@ng-modular-forms/core';
141
+ import { FormHandlerBase } from '@ng-modular-forms/core';
142
142
 
143
- const CONTROL_NAMES = ['fieldA', 'fieldB'] as const;
144
-
145
- type ControlNames = typeof CONTROL_NAMES[number];
143
+ type Controls = {
144
+ 'fieldA': FormControl<string>;
145
+ 'fieldB': FormControl<string>;
146
+ }
146
147
 
147
148
  @Injectable()
148
- export class SectionAHandler extends FormHandlerBase<ControlNames> {
149
+ export class SectionAHandler extends FormHandlerBase<Controls> {
149
150
  override getReactiveLogic(form: FormGroup): Subscription {
150
- this.registerControls(form, CONTROL_NAMES);
151
+ this.initializeForm(form);
151
152
 
152
153
  const subscription = new Subscription();
153
154
 
154
155
  subscription.add(
155
- this.valueChangesOf<string>('fieldA').subscribe((val) => {
156
- const fieldB = getControl<string>('fieldB', form);
156
+ this.valueChangesOf('fieldA').subscribe((val) => {
157
+ const fieldB = this.getControl('fieldB', form);
157
158
 
158
159
  val?.trim()
159
160
  ? fieldB.enable()
@@ -162,7 +163,7 @@ export class SectionAHandler extends FormHandlerBase<ControlNames> {
162
163
  );
163
164
 
164
165
  subscription.add(
165
- this.valueChangesOf<string>('fieldB').subscribe((val) => {
166
+ this.valueChangesOf('fieldB').subscribe((val) => {
166
167
  console.log('Field B changed:', val);
167
168
  }),
168
169
  );
@@ -180,9 +181,9 @@ Handles transformations between API and form. `FormHydrator` and `FormSerializer
180
181
  import { FormMapperBase, getControlValue } from '@ng-modular-forms/core';
181
182
 
182
183
  export class SectionAMapper extends FormMapperBase<
183
- ApiModel, RequestModel, FormModel
184
+ ApiModel, RequestModel, FormModel, FormMapperOptions
184
185
  > {
185
- toRequest(form: FormGroup): RequestModel {
186
+ toRequest(form: FormGroup, _options?: FormMapperOptions): RequestModel {
186
187
  const fieldAValue = getControlValue<string>('fieldA', form);
187
188
  const fieldBValue = getControlValue<string>('fieldB', form);
188
189
  return {
@@ -210,6 +211,11 @@ type ApiModel = {
210
211
  type RequestModel = ApiModel;
211
212
  type FormModel = ApiModel;
212
213
 
214
+ interface FormMapperOptions {
215
+ extraField1?: string;
216
+ extraField2?: string;
217
+ }
218
+
213
219
  /**
214
220
  * These are intentionally separated even if identical.
215
221
  * In real applications:
@@ -363,12 +369,13 @@ All components share a consistent API and are interchangeable between Native and
363
369
  | Input Type | Native Selector | Material Selector |
364
370
  |-----------------|----------------------|-----------------------|
365
371
  | Text / Password | `nmf-text` | `nmf-mat-text` |
372
+ | Lookup | `nmf-lookup` | `nmf-mat-lookup` |
366
373
  | Number | `nmf-number` | `nmf-mat-number` |
367
374
  | Currency | `nmf-currency` | `nmf-mat-currency` |
368
375
  | Date | `nmf-datepicker` | `nmf-mat-datepicker` |
369
- | Time | `nmf-timepicker` | `nmf-mat-timepicker` |
370
376
  | Select | `nmf-select` | `nmf-mat-select` |
371
377
  | Textarea | `nmf-textarea` | `nmf-mat-textarea` |
378
+ | Time | `nmf-timepicker` | `nmf-mat-timepicker` |
372
379
 
373
380
  ### Shared Features
374
381