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
Possibility to add multiple updateOn events #20371
Comments
Is there an update on this issue? |
Actually building an app with save on the fly (without submit button), I use {updateOn:'blur'} for now. Would be helpfull to continue to have native forms like behavior where [enter] in a text field would emit the change and cause formGroup.valueChanges to be called. |
I would like to see this as well, make the updateOn accept an array of values:
|
|
I have the same use-case where blur is used, but when hitting "enter", the value is not committed. A simple example is here: https://angular-qntfgd.stackblitz.io I agree with @pavel-blagodov, but I think an alternative to supporting multiple updateOn values, would simply like to see pending changes committed on submit. Option 1: Support multiple updateOn valuesI think it would be feasible to make this type of change, but would touch a lot of places. Option 2: Commit pending changes on submitI think generally the updateOn options should build on each other. i.e. When a form is submitted, Current workaroundsI have played with two re-usable workarounds, but I do not like them.
Has anyone from Angular team weighed in? I'd be willing to take a pass at a PR if a path was suggested. |
I just made a proposal which addresses this issue over in #31963. I'd be very interested in any feedback folks might have. Specifically, it allows a service to add/remove errors from a control. Because errors are keyed to the service which adds them, one service cannot overwrite another's errors. As an example: const usernameControl = new FormControl();
usernameControl.valueChanges
.pipe(
tap(() => usernameControl.markPending('userService', true)),
debounceTime(500),
switchMap(value => this.userService.doesNameExist(value)),
tap(() => usernameControl.markPending('userService', false)),
map(response => ({
sources: ['MyUserService'],
type: 'errors',
value: response.payload ? { userNameExists: true } : null, // <-- this is an error (or null)
})),
)
.subscribe(usernameControl.source); This hypothetical service is checking the value of a More broadly, this allows you to programmatically add errors to a control however you see fit, either synchronously or asynchronously (in addition to using |
Possible workaround when updateOn is set to "blur": |
This would require a large but shallow PR to change how we store |
[x] Feature request
It would be nice to add support for multiple updateOn: events. e.g updateOn: "blur submit".
There is scenario where single "blur" is not enough.
For example:
In my example, the form will be submitted with empty value in the second filed.
The text was updated successfully, but these errors were encountered: