fix(forms): suppress forms deprecation warning after first

This commit is contained in:
Kara Erickson 2016-06-15 08:49:33 -07:00
parent 17f317d31e
commit 2fd1e88199
2 changed files with 26 additions and 4 deletions

View File

@ -15,6 +15,8 @@ import {composeAsyncValidators, composeValidators, setUpControl, setUpControlGro
export const formDirectiveProvider: any = export const formDirectiveProvider: any =
/*@ts2dart_const*/ {provide: ControlContainer, useExisting: forwardRef(() => NgForm)}; /*@ts2dart_const*/ {provide: ControlContainer, useExisting: forwardRef(() => NgForm)};
let _formWarningDisplayed: boolean = false;
/** /**
* If `NgForm` is bound in a component, `<form>` elements in that component will be * If `NgForm` is bound in a component, `<form>` elements in that component will be
* upgraded to use the Angular form system. * upgraded to use the Angular form system.
@ -76,6 +78,7 @@ export const formDirectiveProvider: any =
* *
* @experimental * @experimental
*/ */
@Directive({ @Directive({
selector: 'form:not([ngNoForm]):not([ngFormModel]),ngForm,[ngForm]', selector: 'form:not([ngNoForm]):not([ngFormModel]),ngForm,[ngForm]',
providers: [formDirectiveProvider], providers: [formDirectiveProvider],
@ -95,13 +98,21 @@ export class NgForm extends ControlContainer implements Form {
@Optional() @Self() @Inject(NG_VALIDATORS) validators: any[], @Optional() @Self() @Inject(NG_VALIDATORS) validators: any[],
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: any[]) { @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: any[]) {
super(); super();
console.warn(` this._displayWarning();
this.form = new ControlGroup(
{}, null, composeValidators(validators), composeAsyncValidators(asyncValidators));
}
private _displayWarning() {
// TODO(kara): Update this when the new forms module becomes the default
if (!_formWarningDisplayed) {
_formWarningDisplayed = true;
console.warn(`
*It looks like you're using the old forms module. This will be opt-in in the next RC, and *It looks like you're using the old forms module. This will be opt-in in the next RC, and
will eventually be removed in favor of the new forms module. For more information, see: will eventually be removed in favor of the new forms module. For more information, see:
https://docs.google.com/document/u/1/d/1RIezQqE4aEhBRmArIAS1mRIZtWFf6JxN_7B4meyWK0Y/pub https://docs.google.com/document/u/1/d/1RIezQqE4aEhBRmArIAS1mRIZtWFf6JxN_7B4meyWK0Y/pub
`); `);
this.form = new ControlGroup( }
{}, null, composeValidators(validators), composeAsyncValidators(asyncValidators));
} }
get submitted(): boolean { return this._submitted; } get submitted(): boolean { return this._submitted; }

View File

@ -19,6 +19,8 @@ export const formDirectiveProvider: any =
useExisting: forwardRef(() => NgFormModel) useExisting: forwardRef(() => NgFormModel)
}; };
let _formModelWarningDisplayed: boolean = false;
/** /**
* Binds an existing control group to a DOM element. * Binds an existing control group to a DOM element.
* *
@ -93,6 +95,7 @@ export const formDirectiveProvider: any =
* *
* @experimental * @experimental
*/ */
@Directive({ @Directive({
selector: '[ngFormModel]', selector: '[ngFormModel]',
providers: [formDirectiveProvider], providers: [formDirectiveProvider],
@ -113,11 +116,19 @@ export class NgFormModel extends ControlContainer implements Form,
@Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[], @Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[],
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) { @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) {
super(); super();
console.warn(` this._displayWarning();
}
private _displayWarning() {
// TODO(kara): Update this when the new forms module becomes the default
if (!_formModelWarningDisplayed) {
_formModelWarningDisplayed = true;
console.warn(`
*It looks like you're using the old forms module. This will be opt-in in the next RC, and *It looks like you're using the old forms module. This will be opt-in in the next RC, and
will eventually be removed in favor of the new forms module. For more information, see: will eventually be removed in favor of the new forms module. For more information, see:
https://docs.google.com/document/u/1/d/1RIezQqE4aEhBRmArIAS1mRIZtWFf6JxN_7B4meyWK0Y/pub https://docs.google.com/document/u/1/d/1RIezQqE4aEhBRmArIAS1mRIZtWFf6JxN_7B4meyWK0Y/pub
`); `);
}
} }
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {