-
Notifications
You must be signed in to change notification settings - Fork 26.2k
feat(forms): add updateOn option to FormBuilder #24599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Let me know how to proceed from here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! It's looking great, just one comment (also needs a rebase).
packages/forms/src/form_builder.ts
Outdated
import {AbstractControl, FormArray, FormControl, FormGroup} from './model'; | ||
import {AbstractControl, AbstractControlOptions, FormArray, FormControl, FormGroup, FormHooks} from './model'; | ||
|
||
export interface GroupExtra { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment here about what this is? For the name, I think OldFormBuilderOptions
is more descriptive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing that we are now at version 6.1 and that no more minor releases are planned before version 7, do you have any thoughts on adding a deprecation notice to these (soon to become) legacy group options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that's a good point. I think yes, but let's do that in a follow-up PR since we need to design a a full deprecation plan.
packages/forms/src/form_builder.ts
Outdated
if (isGroupExtra(extraOrOpts)) { | ||
validators = extraOrOpts.validator != null ? extraOrOpts.validator : null; | ||
asyncValidators = extraOrOpts.asyncValidator != null ? extraOrOpts.asyncValidator : null; | ||
} else if (extraOrOpts != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem right. If isGroupExtra
is satisfied, the updateOn
property will not be set. Instead of the GroupExtra
interface I would try to either lift on the usage of AbstractControlOptions
(which is not public last time I checked) or introduce a public facing interface with all fields being optional. It is public so we should be fine with using it. @kara thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is right as is. We don't want to keep supporting the GroupExtra
API, so I'd prefer not to add options to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but AbstractControlOptions
is fully type-compatible with FormExtra
so there shouldn't be a need for the new interface to be added at all. The bug I described above is real.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's type compatible. asyncValidator
vs asyncValidators
and validator
vs validators
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad. I did not spot the additional s
.
Hi @kara, I renamed the legacy options interface and added a description as per your comment. To my best ability I have rebased on |
@LayZeeDK Can you take a look at the failing CI test? Looks related to the change: https://travis-ci.org/angular/angular/jobs/418858316. Also you'll want to lint with |
@kara You are right. I did not realize that the documentaton example was coupled to an end-to-end test. It should be fixed now, but honestly I have no idea since I am having trouble running the tests on Windows. |
It seems that all that is left is to accept a new golden file for the public API guard. |
@LayZeeDK Yes, the last thing needed to get the tests green is to generate a new golden file. You can do so with:
|
What am I doing wrong?
|
Alright, the command seems to be
I will try rebasing again and then generate a new golden file. |
Please help me out here
|
@LayZeeDK Hmm, I'm not sure what's going on there. Maybe a Windows issue with Bazel? (I'm on a Mac, and the command seems to work as expected). I ran the command for you and added the result in a fixup commit so it wouldn't mess with your authorship. |
@IgorMinar Assigning to you for public API approval. |
I tried it both on Bash, MSYS2, and Ubuntu@Windows Subsystem for Linux. Thank you for helping me out, @kara! I spent more time wrestling Git, testing tools, and build tools than adding code and tests 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for api but let's wait until we branch off 7.0.x before we merge this.
@kara Remember a deprecation plan for the legacy form group options in the |
packages/forms/src/form_builder.ts
Outdated
*/ | ||
export interface LegacyFormGroupOptions { | ||
asyncValidator?: AsyncValidatorFn|AsyncValidatorFn[]|null; | ||
validator?: ValidatorFn|ValidatorFn[]|null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LayZeeDK Some internal Google tests failed because this new type is more restrictive than it was before. Previously we were technically typing the validator
and asyncValidator
properties as any
, so typing as ValidatorFn
is a breaking change for any projects that have strict function types turned on and are using a subtype in their validator function type (e.g. (group: FormGroup) => ValidationErrors|null
instead of (control: AbstractControl) => ValidationErrors|null
or ValidatorFn
).
Technically those types are unsafe and should be updated to match ValidatorFn
(which is why the strict function type option will catch it), but I don't think it makes
sense to create a breaking change for a legacy API that we plan to deprecate.
So let's relax it a bit to {validator?: Function|Function[]|null}
, etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, after chatting with @IgorMinar , I think we need to remove the LegacyFormGroupOptions
type altogether and keep the type exactly the same to avoid breaking changes. When we move to AbstractControlOptions
, we can remove it.
@kara I need your help to modify the golden file for the public API guard again. Thank you! 🙂 |
So does this mean this option will only be available in angular 8, or will it also make it into 7? |
Hopefully 7.1 based on @IgorMinar's comment. |
New presubmit here: http://test/OCL:218760407:BASE:218760432:1540506327680:d2e3abe9 @JohnyDaison @LayZeeDK Should be in 7.1, yes. |
Any firm idea which release this (updateOn via FB group method) will be released in? |
It was released in |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #19163
What is the new behavior?
Support
updateOn
option inFormBuilder
methodsarray
,control
andgroup
.Does this PR introduce a breaking change?
Other information
Special care has been taken to keep backwards compatibility with the
extra
object containing optionalvalidator
andasyncValidator
properties in theFormBuilder#group
method so as not to create breaking changes.Unit tests have been massaged from the form control spec.