Angular Forms: On autocomplete select, define formcontrol value different to input value

Chris Tarasovs

How to mask input for formcontrol name. HTML When the autocomplete is displayed you only see the airport.name. When users select an airport, I would like to display the airport.name in the input value but in formControl I would like to set the airport object as value because when I do a search I need more than a string to find data.

<mat-form-field>
    <input
      matInput
      formControlName="departure_airport"
      #el_departure_input
      class="[ flight-travel-form__airport__input ][ typography-sub-heading ]"
      value=""
      placeholder="Departure"
      [matAutocomplete]="auto"
    />
  </mat-form-field>

  <mat-autocomplete #auto="matAutocomplete">
    <mat-option *ngFor="let airport of active_search_suggestions$ | async" [value]="airport" class="ten-autocomplete">
      {{ airport.name.toLowerCase() }}
      <br>
      <span class="typography-small-text">{{ airport.iata_code }}</span>
      <div *ngIf="airport.object_type === 'airport_group'"> Any Airport</div>
    </mat-option>
  </mat-autocomplete>
</div>
Jana

You could get the whole airport object by simply implementing (onSelectionChange)=selectedAirport(airport) for <mat-option>

Just created a stackblitz for it: https://stackblitz.com/edit/angular-nj3saw

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

#define to double - different value?

From Dev

Angular 5 - Input view with different value

From Dev

To update a formgroup formcontrol value from different formgroup but I do not to want to change the values permanently(Angular)

From Dev

Angular - Select and ngOptions - Define key for value added to model

From Dev

Autocomplete displays key and value using Alpaca forms

From Dev

Angular JS: Pass a forms select option value to database not working

From Dev

Angular JS: Pass a forms select option value to database not working

From Dev

JQuery Select Input By Value

From Dev

Default value and user input in forms

From Dev

Use value from select2:opening call as input to ajax autocomplete data parameter

From Dev

autocomplete ajax - update input with a specified value

From Dev

autocomplete ajax - update input with a specified value

From Dev

autocomplete using angularjs (not able to get input value)

From Dev

Selected autocomplete value not displaying in input box

From Dev

insert into textbox a different value from autocomplete query

From Java

Can't bind to 'formControl' since it isn't a known property of 'input' - Angular2 Material Autocomplete issue

From Dev

Clear autocomplete field value after select address

From Dev

Select jQuery autocomplete value by its id

From Dev

AngularJS Setting the active option of a select element to the value of a different angular object

From Dev

Angular different option value or string given an expression in select dropdown

From Dev

unique value angular reactive forms

From Dev

angular js autocomplete key value array

From Dev

angular js autocomplete key value array

From Dev

Select Attribute value and field value Using jquery autocomplete

From Dev

Input value from different form

From Dev

Operations with Select value and Input value in Ember

From Dev

How to get 'select' value and put into 'input' value?

From Dev

Material UI react autocomplete set different label and different value

From Dev

filter based on SELECT and input value

Related Related

  1. 1

    #define to double - different value?

  2. 2

    Angular 5 - Input view with different value

  3. 3

    To update a formgroup formcontrol value from different formgroup but I do not to want to change the values permanently(Angular)

  4. 4

    Angular - Select and ngOptions - Define key for value added to model

  5. 5

    Autocomplete displays key and value using Alpaca forms

  6. 6

    Angular JS: Pass a forms select option value to database not working

  7. 7

    Angular JS: Pass a forms select option value to database not working

  8. 8

    JQuery Select Input By Value

  9. 9

    Default value and user input in forms

  10. 10

    Use value from select2:opening call as input to ajax autocomplete data parameter

  11. 11

    autocomplete ajax - update input with a specified value

  12. 12

    autocomplete ajax - update input with a specified value

  13. 13

    autocomplete using angularjs (not able to get input value)

  14. 14

    Selected autocomplete value not displaying in input box

  15. 15

    insert into textbox a different value from autocomplete query

  16. 16

    Can't bind to 'formControl' since it isn't a known property of 'input' - Angular2 Material Autocomplete issue

  17. 17

    Clear autocomplete field value after select address

  18. 18

    Select jQuery autocomplete value by its id

  19. 19

    AngularJS Setting the active option of a select element to the value of a different angular object

  20. 20

    Angular different option value or string given an expression in select dropdown

  21. 21

    unique value angular reactive forms

  22. 22

    angular js autocomplete key value array

  23. 23

    angular js autocomplete key value array

  24. 24

    Select Attribute value and field value Using jquery autocomplete

  25. 25

    Input value from different form

  26. 26

    Operations with Select value and Input value in Ember

  27. 27

    How to get 'select' value and put into 'input' value?

  28. 28

    Material UI react autocomplete set different label and different value

  29. 29

    filter based on SELECT and input value

HotTag

Archive