Custom value in Angular Multi select component
27 Apr 20242 minutes to read
The MultiSelect allows user to add a new non-present option to the component value when allowCustomValue
is enabled. while selecting the new custom value customValueSelection
event will be triggered.
The following sample demonstrates configuration of custom value support with the MultiSelect component.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { MultiSelectModule } from '@syncfusion/ej2-angular-dropdowns'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { Component } from '@angular/core';
@Component({
imports: [
FormsModule, ReactiveFormsModule, MultiSelectModule, ButtonModule
],
standalone: true,
selector: 'app-root',
// specifies the template string for the MultiSelect component
template: `<ejs-multiselect id='multiselectelement' [dataSource]='sportsData' [fields]='fields' [allowCustomValue]='true' [placeholder]='placeholder'></ejs-multiselect>`
})
export class AppComponent {
constructor() {
}
// defined the array of data
public sportsData: { [key: string]: Object }[] = [
{ id: 'game1', sports: 'Badminton' },
{ id: 'game2', sports: 'Football' },
{ id: 'game3', sports: 'Tennis' }
];
// map the appropriate column
public fields: Object = { text: 'sports', value: 'id' };
// set the placeholder to the MultiSelect input
public placeholder: string = 'Select games';
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));