feat(forms): changed the selector of TemplatdrivenFormDirective to match <form>

This commit is contained in:
vsavkin 2015-06-01 13:11:34 -07:00
parent 652ed0cf6d
commit 6bef1c4169
2 changed files with 26 additions and 7 deletions

View File

@ -13,7 +13,10 @@ import {setUpControl} from './shared';
const formDirectiveBinding = CONST_EXPR(new Binding( const formDirectiveBinding = CONST_EXPR(new Binding(
ControlContainerDirective, {toAlias: FORWARD_REF(() => TemplateDrivenFormDirective)})); ControlContainerDirective, {toAlias: FORWARD_REF(() => TemplateDrivenFormDirective)}));
@Directive({selector: '[form]', hostInjector: [formDirectiveBinding]}) @Directive({
selector: 'form:not([ng-no-form]):not([form-model]),ng-form,[ng-form]',
hostInjector: [formDirectiveBinding]
})
export class TemplateDrivenFormDirective extends ControlContainerDirective implements export class TemplateDrivenFormDirective extends ControlContainerDirective implements
FormDirective { FormDirective {
form: ControlGroup; form: ControlGroup;

View File

@ -427,11 +427,11 @@ export function main() {
inject([TestBed], fakeAsync(tb => { inject([TestBed], fakeAsync(tb => {
var ctx = MyComp.create({name: null}); var ctx = MyComp.create({name: null});
var t = `<div form> var t = `<form>
<div control-group="user"> <div control-group="user">
<input type="text" control="login"> <input type="text" control="login">
</div> </div>
</div>`; </form>`;
tb.createView(MyComp, {context: ctx, html: t}) tb.createView(MyComp, {context: ctx, html: t})
.then((view) => { .then((view) => {
@ -448,14 +448,30 @@ export function main() {
flushMicrotasks(); flushMicrotasks();
}))); })));
it("should not create a template-driven form when ng-no-form is used",
inject([TestBed], fakeAsync(tb => {
var ctx = MyComp.create({name: null});
var t = `<form ng-no-form>
</form>`;
tb.createView(MyComp, {context: ctx, html: t})
.then((view) => {
view.detectChanges();
expect(view.rawView.elementInjectors.length).toEqual(0);
});
flushMicrotasks();
})));
it("should remove controls", inject([TestBed], fakeAsync(tb => { it("should remove controls", inject([TestBed], fakeAsync(tb => {
var ctx = MyComp.create({name: 'show'}); var ctx = MyComp.create({name: 'show'});
var t = `<div form> var t = `<form>
<div *ng-if="name == 'show'"> <div *ng-if="name == 'show'">
<input type="text" control="login"> <input type="text" control="login">
</div> </div>
</div>`; </form>`;
tb.createView(MyComp, {context: ctx, html: t}) tb.createView(MyComp, {context: ctx, html: t})
.then((view) => { .then((view) => {
@ -481,11 +497,11 @@ export function main() {
var ctx = MyComp.create({name: 'show'}); var ctx = MyComp.create({name: 'show'});
var t = `<div form> var t = `<form>
<div *ng-if="name=='show'" control-group="user"> <div *ng-if="name=='show'" control-group="user">
<input type="text" control="login"> <input type="text" control="login">
</div> </div>
</div>`; </form>`;
tb.createView(MyComp, {context: ctx, html: t}) tb.createView(MyComp, {context: ctx, html: t})