-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
139 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...parametrise-action-dialog/components/formly-autocomplete/formly-autocomplete.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
/* | ||
* Copyright (c) 2023 Thomas Hansen - For license inquiries you can contact thomas@ainiro.io. | ||
*/ | ||
|
||
// Angular and system imports. | ||
import { FieldType, FieldTypeConfig } from '@ngx-formly/core'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { FormControl } from '@angular/forms'; | ||
import { Observable, map, startWith } from 'rxjs'; | ||
|
||
// Application specific imports | ||
|
||
/** | ||
* Formly SQL extension field. | ||
*/ | ||
@Component({ | ||
selector: 'app-formly-autocomplete', | ||
template: ` | ||
<mat-form-field class="w-100 standalone-field mb-4"> | ||
<mat-label>{{field.props.label}}</mat-label> | ||
<input type="text" | ||
[id]="field.key" | ||
[placeholder]="field.props.label" | ||
matInput | ||
[formControl]="control" | ||
[matAutocomplete]="auto"> | ||
<mat-autocomplete #auto="matAutocomplete"> | ||
<mat-option | ||
*ngFor="let option of filteredOptions | async;" | ||
[value]="option.value">{{option.label}}</mat-option> | ||
</mat-autocomplete> | ||
</mat-form-field> | ||
`, | ||
styleUrls: ['./formly-autocomplete.scss'] | ||
}) | ||
export class FormlyAutocompleteComponent extends FieldType<FieldTypeConfig> implements OnInit { | ||
|
||
control = new FormControl(''); | ||
filteredOptions: Observable<string[]>; | ||
|
||
constructor() { | ||
|
||
super(); | ||
} | ||
|
||
ngOnInit() { | ||
|
||
this.filteredOptions = this.control.valueChanges.pipe( | ||
startWith(''), | ||
map(value => this._filter(value || '')), | ||
); | ||
this.control.setValue(this.field.model[<string>this.field.key]); | ||
this.control.valueChanges.subscribe((val: string) => { | ||
this.model[<string>this.field.key] = val; | ||
}); | ||
} | ||
|
||
/* | ||
* Private helper methods. | ||
*/ | ||
|
||
private _filter(value: string): any[] { | ||
|
||
const filterValue = value.toLowerCase(); | ||
return (<any[]>this.field.props.options).filter(option => option.label.toLowerCase().includes(filterValue)); | ||
}} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters