0

I have a form below with multiple elements. One element is an input with a custom directive for getting google location data. The other element is a file upload element.

When I enter in a value (in focus) in the top element and press enter, it triggers 'fileChangeEvent()' event in the #fileInput element.

I'm having a hard time understanding why?

FYI - I tried changing

(change)="fileChangeEvent($event)"

to

(click)="fileChangeEvent($event)"

and it still gets triggered

Form -

<form [formGroup]="editForm">

  // pressing enter, with this element in focus, triggers fileChangeEvent($event) in #fileInput element below
  <input #city appGooglePlaces (onSelect)="setAddress($event)" formControlName="city" class="form-control google-place-input">


  <button (click)="fileInput.click()" class="btn btn-yb w-100">Upload Photo</button>
  <input type="file" #fileInput (change)="fileChangeEvent($event)" />

</form>
user1186050
  • 12,296
  • 22
  • 123
  • 274

1 Answers1

2

Have a look at this issue, I think your problem is your button is in a form therefore the default action for the enter key is to submit the form. By default your button is type "submit".

Hopey One
  • 1,474
  • 3
  • 9