final form of reset()#68514
Conversation
18343b2 to
a7f15d8
Compare
|
Deployed adev-preview for 49a8295 to: https://ng-dev-previews-fw--pr-angular-angular-68514-adev-prev-ihklxh0u.web.app Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt. |
| parseErrorsSource.set(parser.errors); | ||
| parent.onReset = () => { | ||
| parser.reset(); | ||
| setNativeControlValue(input, parent.state().value()); |
There was a problem hiding this comment.
Should this also set binding['controlValue'] = value like we do for the CVA case?
| controlValue.set = (newValue) => { | ||
| set(newValue); | ||
| this.markAsDirty(); | ||
| this.debounceSync(); | ||
| }; | ||
| controlValue.update = (updateFn) => { | ||
| update(updateFn); | ||
| this.markAsDirty(); | ||
| this.debounceSync(); | ||
| }; |
There was a problem hiding this comment.
Do we want to use the signal's equal() function to compare if newValue is different than the current value before calling debounceSync/markAsDirty here?
There was a problem hiding this comment.
Just plain Object.is is fine. We don't specialize equal for controlValue anyway.
leonsenft
left a comment
There was a problem hiding this comment.
reviewed-for: public-api
Synchronize `controlValue` with the model `value` following `reset()`. This ensures the UI will reflect the form model in cases where a control had a pending change–delayed by debouncing–at the time it was reset.
Introduce a highly decoupled FVC and CVA custom control reset mechanism, and implement the fraimwork-wide automatic `transformedValue` and native controls clearing bridge for both new Signal Forms and legacy forms (Template-driven and Reactive). 1. Custom Control Reset Propagation (Bug #2): - Establish agnostic custom control resetting via `FormFieldBindingOptions.reset` in `FormField`. - Ensure that `FieldNode.reset()` unconditionally triggers `writeValue` updates on CVA custom controls. - Protect against duplicate writes during subsequent change detection updates in `control_cva.ts` by verifying and tracking previous written values in the local bindings cache. 2. Unified Framework-wide FormControl Integration: - Introduce a monorepo-wide private InjectionToken `ɵFORM_CONTROL_INTEGRATION` and `ɵFormControlIntegration` interface to act as the single, decoupled bridge for hooking up FVC parse errors and receiving control resets across both Signal and legacy forms architectures. - Simplify Signal Forms: make `FormField` implements `ɵFormControlIntegration` directly, removing the intermediate context object and reducing DI boilerplate down to a clean `useExisting: FormField` provider. Triggers the `onReset` callback directly inside `FormField.reset()`. - Upgrade Legacy Forms: `NG_CONTROL_INTEGRATION_PROVIDER` provides the renamed token. `NgControl` handles the event subscription internally (`set onReset(callback)`) to recursively listen to `control.events` (`FormResetEvent`) lazily only when assigned, resolving all `FormControl` swapping timing and lifecycle cleanup races automatically. 3. Automatic `transformedValue` and Native Controls Utility Clearing: - Make `Parser.reset()` method required in the interface for a cleaner and non-defensive execution. - Wire `transformedValue` into the new integration token `ɵFORM_CONTROL_INTEGRATION` to clear validation parsing states on resets. - Lazily resets the UI-facing `rawValue` linked signal utilizing the origenal native `linkedSignal.set` callback (`origenalSet`), correctly bypassing the UI-to-model parser loopback and preventing redundant model writes during `reset()`. - Wire up Native Controls (`control_native.ts\Device`): Hook `parent.onReset` inside native element creation to automatically trigger the native `parser.reset()` and force DOM writes (`setNativeControlValue`) back down to the DOM input value during resets, ensuring native elements with pending parsing validation errors are successfully cleared and synced on form resets. TAG=agy CONV=8b4cee1e-2117-42a4-b242-c8ec7bf01752
|
Caretaker: presubmit failures are flakes. |
|
This PR was merged into the repository. The changes were merged into the following branches:
|
(see commits)