Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 79d9be3

Browse files
committed
Revert "feat(forms): add ability to clear a FormRecord (#50750)" (#58315)
This reverts commit 3e7d724. PR Close #58315
1 parent a5b0394 commit 79d9be3

File tree

3 files changed

+1
-70
lines changed

3 files changed

+1
-70
lines changed

‎goldens/public-api/forms/index.api.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,6 @@ export interface FormRecord<TControl> {
534534
addControl(name: string, control: TControl, options?: {
535535
emitEvent?: boolean;
536536
}): void;
537-
clear(options?: {
538-
emitEvent?: boolean;
539-
}): void;
540537
contains(controlName: string): boolean;
541538
getRawValue(): {
542539
[key: string]: ɵRawValue<TControl>;

‎packages/forms/src/model/form_group.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -724,25 +724,7 @@ export const isFormGroup = (control: unknown): control is FormGroup => control i
724724
*/
725725
export class FormRecord<TControl extends AbstractControl = AbstractControl> extends FormGroup<{
726726
[key: string]: TControl;
727-
}> {
728-
/**
729-
* Clear all controls from this record.
730-
*
731-
* This method also updates the value and validity of the control.
732-
*
733-
* @param options Specifies whether this FormGroup instance should emit events after a
734-
* control is removed.
735-
* * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
736-
* `valueChanges` observables emit events with the latest status and value when the controls are
737-
* removed. When false, no events are emitted.
738-
*/
739-
clear(options: {emitEvent?: boolean} = {}): void {
740-
this._forEachChild((child) => child._registerOnCollectionChange(() => {}));
741-
this.controls = {};
742-
this.updateValueAndValidity({emitEvent: options.emitEvent});
743-
this._onCollectionChange();
744-
}
745-
}
727+
}> {}
746728

747729
export interface FormRecord<TControl> {
748730
/**
@@ -766,19 +748,6 @@ export interface FormRecord<TControl> {
766748
*/
767749
removeControl(name: string, options?: {emitEvent?: boolean}): void;
768750

769-
/**
770-
* Clear all controls from this record.
771-
*
772-
* This method also updates the value and validity of the control.
773-
*
774-
* @param options Specifies whether this FormGroup instance should emit events after a
775-
* control is removed.
776-
* * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
777-
* `valueChanges` observables emit events with the latest status and value when the controls are
778-
* removed. When false, no events are emitted.
779-
*/
780-
clear(options?: {emitEvent?: boolean}): void;
781-
782751
/**
783752
* Replace an existing control.
784753
*

‎packages/forms/test/form_group_spec.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
FormArray,
1414
FormControl,
1515
FormGroup,
16-
FormRecord,
1716
ValidationErrors,
1817
Validators,
1918
ValueChangeEvent,
@@ -2587,39 +2586,5 @@ import {StatusChangeEvent} from '../src/model/abstract_model';
25872586
});
25882587
expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
25892588
});
2590-
2591-
describe('clear()', () => {
2592-
let c1: FormControl;
2593-
let c2: FormControl;
2594-
let r: FormRecord;
2595-
2596-
beforeEach(() => {
2597-
c1 = new FormControl('one');
2598-
c2 = new FormControl('two');
2599-
r = new FormRecord({one: c1, two: c2});
2600-
});
2601-
2602-
it('should remove control if new control is null', () => {
2603-
r.clear();
2604-
expect(r.controls['one']).not.toBeDefined();
2605-
expect(r.controls['two']).not.toBeDefined();
2606-
expect(r.value).toEqual({});
2607-
});
2608-
2609-
it('should only emit value change event once', () => {
2610-
const logger: string[] = [];
2611-
r.valueChanges.subscribe(() => logger.push('change!'));
2612-
r.clear();
2613-
expect(logger).toEqual(['change!']);
2614-
});
2615-
2616-
it('should not emit event when `FormGroup.clearControls` called with `emitEvent: false`', () => {
2617-
const logger: string[] = [];
2618-
r.valueChanges.subscribe(() => logger.push('value change'));
2619-
r.statusChanges.subscribe(() => logger.push('status change'));
2620-
r.clear({emitEvent: false});
2621-
expect(logger).toEqual([]);
2622-
});
2623-
});
26242589
});
26252590
})();

0 commit comments

Comments
 (0)