File

projects/cobbler-frontend/src/app/common/multi-select-strict/multi-select-strict.component.ts

Implements

ControlValueAccessor

Metadata

Index

Properties
Methods
Inputs

Inputs

label
Type : string
Default value : ''
options
Type : string[]
Default value : []

Methods

registerOnChange
registerOnChange(fn: (value: string[]) => void)
Parameters :
Name Type Optional
fn function No
Returns : void
registerOnTouched
registerOnTouched(fn: () => void)
Parameters :
Name Type Optional
fn function No
Returns : void
selectionChange
selectionChange(newValue: string[])
Parameters :
Name Type Optional
newValue string[] No
Returns : void
setDisabledState
setDisabledState(isDisabled: boolean)
Parameters :
Name Type Optional
isDisabled boolean No
Returns : void
writeValue
writeValue(obj: string[])
Parameters :
Name Type Optional
obj string[] No
Returns : void

Properties

isDisabled
Type : unknown
Default value : false
onChange
Type : function
Default value : () => {...}
onTouched
Type : function
Default value : () => {...}
value
Type : string[]
Default value : []
import { Component, Input } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { MatCardModule } from '@angular/material/card';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatSelectModule } from '@angular/material/select';

@Component({
  selector: 'cobbler-multi-select-strict',
  imports: [MatFormFieldModule, MatSelectModule, MatCardModule],
  providers: [
    {
      provide: NG_VALUE_ACCESSOR,
      multi: true,
      useExisting: MultiSelectStrictComponent,
    },
  ],
  templateUrl: './multi-select-strict.component.html',
  styleUrl: './multi-select-strict.component.scss',
})
export class MultiSelectStrictComponent implements ControlValueAccessor {
  @Input() label = '';
  @Input() options: string[] = [];

  value: string[] = [];
  isDisabled = false;
  onChange: (value: string[]) => void = () => {};
  onTouched: () => void = () => {};

  writeValue(obj: string[]): void {
    this.value = obj || [];
  }
  registerOnChange(fn: (value: string[]) => void): void {
    this.onChange = fn;
  }
  registerOnTouched(fn: () => void): void {
    this.onTouched = fn;
  }
  setDisabledState(isDisabled: boolean): void {
    this.isDisabled = isDisabled;
  }

  selectionChange(newValue: string[]): void {
    this.value = newValue;
    this.onChange(newValue);
    this.onTouched;
  }
}
<mat-card appearance="outlined" class="form-field-full-widths">
  <mat-card-header>
    <mat-card-title>{{ label }}</mat-card-title>
  </mat-card-header>
  <mat-form-field class="form-field">
    <mat-select
      [value]="value"
      multiple
      [disabled]="isDisabled"
      (selectionChange)="selectionChange($event.value)"
      ><mat-select-trigger>
        {{ value[0] || "" }}
        @if (value.length > 1) {
          <span class="additional-selection">
            (+{{ value.length - 1 }}
            {{ value.length === 2 ? "other" : "others" }})
          </span>
        }
      </mat-select-trigger>
      @for (option of options; track option) {
        <mat-option [value]="option">{{ option }}</mat-option>
      }
    </mat-select>
  </mat-form-field>
</mat-card>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""