feat(forms): support imperative disable and enable in SignalFormControl#69683
Open
franmc01 wants to merge 1 commit into
Open
feat(forms): support imperative disable and enable in SignalFormControl#69683franmc01 wants to merge 1 commit into
franmc01 wants to merge 1 commit into
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Previously SignalFormControl threw when disable() or enable() was called,
which made it impossible to disable a FormGroup or FormArray containing
one, since the parent's disable() calls disable({onlySelf: true}) on
every child control.
The imperative disabled status is bridged through signal forms' own rule
system: the user schema is wrapped with a root-level disabled rule driven
by an internal signal that disable(), enable(), and boxed reset() write.
Status, enabled, parent value exclusion, and onDisabledChange callbacks
all derive from the existing machinery.
enable() only clears the imperatively set status; a control disabled by a
schema rule stays disabled. Boxed reset({value, disabled}) is supported
instead of throwing. Parent pristine and touched recalculation mirrors
reactive forms via _updatePristine and _updateTouched so sibling state is
never reset, and the control's own status emissions honor emitEvent:
false through last-emitted-status deduplication.
Fixes angular#68882
444fd06 to
d9db3b1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
PR Type
What is the current behavior?
SignalFormControl.disable()andenable()throw. BecauseFormGroup.disable()callsdisable()on every child, a group or array containing aSignalFormControlcannot be disabled at all.reset({value, disabled})also throws.Issue Number: #68882
What is the new behavior?
disable()/enable()work, both directly and from a parentFormGroup/FormArray.disabledrule on the control's internal schema, so status,enabled, parent value exclusion, andonDisabledChangecallbacks derive from the existing signal forms machinery.enable()only clears the imperatively set status; a control disabled by a schemadisabledrule stays disabled.reset({value, disabled})is supported instead of throwing.emitEvent: falseis honored for the control's own status emissions.Not done in this PR: extending
AbstractControl<T>for a typedvalue(also requested in #68882). That changes the typed public API surface and is left as a follow-up.Does this PR introduce a breaking change?
Other information
Fixes #68882