All Components

Forms Support

You can use the MultiSelect in template-driven or reactive forms.

The component accepts values of the complex (objects) or the primitive (strings or numbers) type. To specify the value type, set the valuePrimitive property. By default, it is set to false.

Template-Driven Forms

The template-driven forms enable you to bind the MultiSelect to the model by using the ngModel directive.

The following example demonstrates how to accomplish a two-way data binding by using the ngModel directive. The model field is a complex value.

@Component({
  selector: 'my-app',
  template: `
    <form #form="ngForm">
      <div class="example-config">
        The selected values are <strong>{{ gender | json }}</strong>
      </div>
      <div class="example-wrapper">
        <p>Select Gender:</p>
        <kendo-multiselect
            name="gender"
            [data]="genders"
            [textField]="'text'"
            [valueField]="'value'"
            [(ngModel)]="gender"
        >
        </kendo-multiselect>
      </div>  
    </form>
  `
})
class AppComponent {
    public genders: Array<{ text: string, value: number }> = [
        { text: "Male", value: 1 },
        { text: "Female", value: 2 },
        { text: "Other", value: 3 }
    ];

    public gender = [{ text: "Female", value: 2 }];
}

The following example demonstrates how to accomplish a two-way data binding by using the ngModel directive. The model field is a primitive value.

@Component({
  selector: 'my-app',
  template: `
    <form #form="ngForm">
      <div class="example-config">
        The selected values are <strong>{{ gender | json }}</strong>
      </div>
      <p>Select Gender:</p>
      <kendo-multiselect
          name="gender"
          [data]="genders"
          [textField]="'text'"
          [valueField]="'value'"
          [valuePrimitive]="true"
          [(ngModel)]="gender"
      >
      </kendo-multiselect>
    </form>
  `
})
class AppComponent {
    public genders: Array<{ text: string, value: number }> = [
        { text: "Male", value: 1 },
        { text: "Female", value: 2 },
        { text: "Other", value: 3 }
    ];

    public gender = [2];
}

Reactive Forms

The FormGroup provides a way to render reactive forms. For more details, refer to the Angular Documentation.

The following example demonstrates how to use the MultiSelect in a reactive form with a primitive value binding.
 

import {
    FormsModule,
    ReactiveFormsModule,
    FormGroup,
    FormControl
} from '@angular/forms';

@Component({
  selector: 'my-app',
  template: `
    <form [formGroup]="myForm">
      <div class="example-config">
        The form.gender value is: <strong>{{ myForm.controls.gender.value | json }}</strong>
      </div>
      <p>Select Gender:</p>
      <kendo-multiselect
          formControlName="gender"
          [data]="genders"
          [textField]="'text'"
          [valueField]="'value'"
          [valuePrimitive]="true"
      >
      </kendo-multiselect>
    </form>
  `
})
class AppComponent {
    public genders: Array<{ text: string, value: number }> = [
        { text: "Male", value: 1 },
        { text: "Female", value: 2 },
        { text: "Other", value: 3 }
    ];

    public myForm: FormGroup = new FormGroup({
        gender: new FormControl([2])
    });
}

The following example demonstrates how to use the MultiSelect in a reactive form with a complex value binding.
 

import {
    FormsModule,
    ReactiveFormsModule,
    FormGroup,
    FormControl
} from '@angular/forms';

@Component({
  selector: 'my-app',
  template: `
    <form [formGroup]="myForm">
      <div class="example-config">
        The form.gender value is: <strong>{{ myForm.controls.gender.value | json }}</strong>
      </div>
      <p>Select gender</p>
      <kendo-multiselect
          formControlName="gender"
          [data]="genders"
          [textField]="'text'"
          [valueField]="'value'"
      >
      </kendo-multiselect>
    </form>
  `
})
class AppComponent {
    public genders: Array<{ text: string, value: number }> = [
        { text: "Male", value: 1 },
        { text: "Female", value: 2 },
        { text: "Other", value: 3 }
    ];

    public myForm: FormGroup = new FormGroup({
        gender: new FormControl([{ text: "Female", value: 2 }])
    });
}
In this article