feat(forms): add updateOn submit option to FormControls (#18514)
This commit is contained in:
@ -134,6 +134,7 @@ export class FormGroupDirective extends ControlContainer implements Form,
|
||||
|
||||
onSubmit($event: Event): boolean {
|
||||
this._submitted = true;
|
||||
this._syncPendingControls();
|
||||
this.ngSubmit.emit($event);
|
||||
return false;
|
||||
}
|
||||
@ -145,6 +146,16 @@ export class FormGroupDirective extends ControlContainer implements Form,
|
||||
this._submitted = false;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
_syncPendingControls() {
|
||||
this.form._syncPendingControls();
|
||||
this.directives.forEach(dir => {
|
||||
if (dir.control._updateOn === 'submit') {
|
||||
dir.viewToModelUpdate(dir.control._pendingValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
_updateDomValue() {
|
||||
this.directives.forEach(dir => {
|
||||
|
@ -84,25 +84,25 @@ function setUpViewChangePipeline(control: FormControl, dir: NgControl): void {
|
||||
control._pendingValue = newValue;
|
||||
control._pendingDirty = true;
|
||||
|
||||
if (control._updateOn === 'change') {
|
||||
dir.viewToModelUpdate(newValue);
|
||||
control.markAsDirty();
|
||||
control.setValue(newValue, {emitModelToViewChange: false});
|
||||
}
|
||||
if (control._updateOn === 'change') updateControl(control, dir);
|
||||
});
|
||||
}
|
||||
|
||||
function setUpBlurPipeline(control: FormControl, dir: NgControl): void {
|
||||
dir.valueAccessor !.registerOnTouched(() => {
|
||||
if (control._updateOn === 'blur') {
|
||||
dir.viewToModelUpdate(control._pendingValue);
|
||||
if (control._pendingDirty) control.markAsDirty();
|
||||
control.setValue(control._pendingValue, {emitModelToViewChange: false});
|
||||
}
|
||||
control.markAsTouched();
|
||||
control._pendingTouched = true;
|
||||
|
||||
if (control._updateOn === 'blur') updateControl(control, dir);
|
||||
if (control._updateOn !== 'submit') control.markAsTouched();
|
||||
});
|
||||
}
|
||||
|
||||
function updateControl(control: FormControl, dir: NgControl): void {
|
||||
dir.viewToModelUpdate(control._pendingValue);
|
||||
if (control._pendingDirty) control.markAsDirty();
|
||||
control.setValue(control._pendingValue, {emitModelToViewChange: false});
|
||||
}
|
||||
|
||||
function setUpModelChangePipeline(control: FormControl, dir: NgControl): void {
|
||||
control.registerOnChange((newValue: any, emitModelEvent: boolean) => {
|
||||
// control -> view
|
||||
|
Reference in New Issue
Block a user