Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Autocomplete Component - Cannot get Reactive Form with existing value work #235

Open
Assignees
xidedix
@bernik1980

Description

@bernik1980

I have the following autocomplete input:

<input cAutocomplete       highlightOptionsOnSearch       allowOnlyDefinedOptions       showHints       [loading]="isPersonsLoading"       [options]="persons"       [search]="{external: true, global: true}"       [delay]="500"       (inputChange)="personsLoad($event)"             formControlName="person"       [valid]="itemForm.controls['person'].touched ? itemForm.controls['person'].valid : undefined" />

persons is a lazy loaded list after (inputChange):

persons: AutocompleteOption[] = []`
 personsLoad(input: string) {   if (!input) {     return   }   this.isPersonsLoading = true   let query = new PagedQuery()   query.filter = input   query.sort = { column: 'LastName' }   this.http.get<PagedResult<Person>>('/api/persons', { params: query.toHttpParams() }).subscribe({     next: (result) => {       this.persons = result.results.map((person) => <AutocompleteOption>{ label: `${person.lastName}, ${person.firstName}`, value: person.id })     }   }).add(() => {     this.isPersonsLoading = false   }) }

The form definition:

itemForm = new FormGroup({  person: new FormControl('', Validators.required)}

And the important part, setting the form value initally:

this.itemForm.get('person')!.setValue(`${this.item.person?.lastName}, ${this.item.person?.firstName}`)

And now whenever I change the autocomplete input, the list of options is not displayed, but the input resets immediatly to the inital value.

If no initial value is set, the input works as expected.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp