ng2-ui / auto-complete

Angular Auto Complete component and directive
https://ng2-ui.github.io/dist/#/auto-complete
MIT License
279 stars 123 forks source link

Form Validation with angular 2.4 #311

Closed vicabelotelova closed 6 years ago

vicabelotelova commented 6 years ago

Hey everybody! I have a problem with auto complete and my validation

i have form group and control in My html

<div class="form-group" [formGroup]="CreateObject">
      <label class="col-md-4 control-label" for="adress">Region<span class="RedStar">*</span>:</label>
        <div class="form-group col-md-6" [class.has-error]="isControlValid('RegionControl')">
          <div
            ngui-auto-complete
             formControlName="RegionControl"
            [source]="RegionsArray"
            [list-formatter]="autocompleListFormatter"
            (valueChanged)="searchCitiesInBase($event)"
            display-property-name="FullName"
            >
            <input class="form-control"  >
            <p class="text-danger" *ngIf="isControlValid('RegionControl')">Error</p>
            </div>
            </div>
        </div>

And my ts file


buildForm(){
    this.CreateReObject =  this.formBuilder.group({
      RegionControl: this.formBuilder.control('', Validators.required)
    });

isControlValid(control: string){
    return !this.CreateReObject.get(control).valid && this.CreateReObject.get(control).touched;
  }

Перевести

when i was touched input and chose a option. Validators.required said this input is invalid. Why is it happend? And how i will can fix it

GeorgeSokolovsky commented 6 years ago

Can you create a plunker for it? Because I tried to reproduce it by myself and seems like all work as expected.