1.0.9 • Published 3 years ago

@smithbrianscott/bs-material-autocomplete v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Angular Material Autocomplete

Description

A reactive form single control angular material autocomplete component. bs-material-autocomplete

See Demo (Stackblitz)

Usage

npm install @smithbrianscott/bs-material-autocomplete

Add the styles you prefer from the @angular/material npm package to the angular.json file.

"styles": {
  "node_module/@angular/material/prebuilt-themes/indigo-pink.css"
}

Also add the styles for the material icons. (You can also import this in your CSS)

<link
  href="https://fonts.googleapis.com/icon?family=Material+Icons"
  rel="stylesheet"
/>

Add BsMaterialAutocompleteModule to your @NgModule imports.

import { NgModule } from "@angular/core";

import { BsMaterialAutocompleteModule } from "@smithbrianscott/bs-material-autocomplete";

@NgModule({
  imports: [BsMaterialAutocompleteModule],
})
export class FeatureModule {}

Add the autocomplete control using the selector <bs-material-autocomplete>.

You must use the following class. You can import this from the library. import { BsSearchInfo } from '@smithbrianscott/bs-material-autocomplete/lib/bs-search-info';

export class BsSearchInfo {
  id: number;
  searchKeywords: string;
  displayValue: string;
  data: any;
}
NameDescription
idPrimary key value from your dataset
searchKeywordsString of searchable value for the autocomplete search. i.e. 'john,doe,john doe,johndoe@gmail.com,2384756'
displayValueDisplayed value after selecting an item. i.e. 'John Doe'
dataNot required. Can bind your original object data value for use when item selected.

TS Component

export class MyAppComponent implements OnInit {
  myForm: FormGroup;
  searchItems: BsSearchInfo[] = [];

  constructor(private fb: FormBuilder) {}

  ngOnInit() {
    this.myForm = this.fb.group({
      personID: [null],
      person: [null, [Validators.required]], // Set required on this control if required
    });
  }
}

HTML Component

<bs-material-autocomplete
  [placeholder]="'Autocomplete Placeholder'"
  [form]="myForm"
  [idValueControlName]="'personID'"
  [controlName]="'person'"
  [items]="searchItems"
>
</bs-material-autocomplete>

API

NameRequiredDefaultDescription
@Input() placeholder: string;RequiredSearchPlaceholder value
@Input() controlName: string;RequiredcontrolNameForm control name value from your form control for the selected object
@Input() idValueControlName: string;OptionalidForm control name value from your form control for the selected ID value
@Input() form: FormGroup;RequiredThe FormGroup instance that contains the controlName
@Input() items: BsSearchInfo[];Required[]The list of items to search using autocomplete
@Input() invalidSelectionErrorMessage: string;OptionalInvalid selection, please search againDisplayed message when searched item does not exist
@Input() requiredErrorMessage: string;OptionalRequiredDisplayed required message
@Output() onSelected: EventEmitter;OptionalAn output event of the item selected
1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago