oferh / ng2-completer

Angular 2 autocomplete component
http://oferh.github.io/ng2-completer/
MIT License
347 stars 172 forks source link

How to use ng2-completer with Data Driven (Reactive) Form #88

Open shamim4063 opened 8 years ago

shamim4063 commented 8 years ago

I have following form which I use for validation. Now I want to use ng2-completer with this form. Is it possible?

    <!--<form [formGroup]="complexForm" (ngSubmit)="submitForm(complexForm.value)">
        <div class="form-group" [ngClass]="{'has-error':!complexForm.controls['firstName'].valid}">
            <label>First Name:</label>
            <input class="form-control" type="text" placeholder="John" [formControl]="complexForm.controls['firstName']">
            <div *ngIf="complexForm.controls['firstName'].hasError('required') && complexForm.controls['firstName'].touched" class="alert alert-danger">You must include a first name.</div>
        </div>

        <div class="form-group">
            <label>Last Name</label>              
            <input class="form-control" type="text" placeholder="Doe" [formControl]="complexForm.controls['lastName']">
        </div>
        <button type="submit" class="btn btn-default" [disabled]="!complexForm.valid">Submit</button>
    </form>
ghost commented 8 years ago

@shamim4063 I have used ng2-completer with Reactive Forms, not sure if it is recommended to use both type of forms, but yes it's possible.

Crevil commented 7 years ago

I'm not able to use this module with reactive forms. The ngModel attribute is not allowed with a parent fromGroup attribute (the base of reactive forms).

Any considerations making this possible?

rajeshthb commented 7 years ago

any update on this feature ?

oferh commented 7 years ago

can you provide a plunkr for it?

misham commented 7 years ago

@oferh here's a plunk with it: https://plnkr.co/edit/ifPKbX?p=info

Just wrapping the example template in Reactive Form tag causes the error.

oferh commented 7 years ago

@misham thanks!

You should import ReactiveFormsModule in AppModule and add formControlName to the control and then it works https://plnkr.co/edit/xU98ux?p=preview