-import { Component, Input, forwardRef } from '@angular/core'
-import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms'
-import { SelectOptionsItem } from './select-options.component'
+import { Component, forwardRef, Input, OnInit } from '@angular/core'
+import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
+import { SelectOptionsItem } from '../../../../types/select-options-item.model'
-export type ItemSelectCheckboxValue = { id?: string | number, group?: string } | string
+export type ItemSelectCheckboxValue = { id?: string, group?: string } | string
@Component({
selector: 'my-select-checkbox',
}
]
})
-export class SelectCheckboxComponent implements ControlValueAccessor {
+export class SelectCheckboxComponent implements OnInit, ControlValueAccessor {
@Input() availableItems: SelectOptionsItem[] = []
@Input() selectedItems: ItemSelectCheckboxValue[] = []
@Input() selectableGroup: boolean
@Input() selectableGroupAsModel: boolean
- @Input() maxSelectedItems: number
+ @Input() placeholder: string
+
+ disabled = false
+
+ ngOnInit () {
+ if (!this.placeholder) this.placeholder = $localize`Add a new option`
+ }
propagateChange = (_: any) => { /* empty */ }
} else {
this.selectedItems = items
}
-
- this.propagateChange(this.selectedItems)
}
registerOnChange (fn: (_: any) => void) {
this.propagateChange(this.selectedItems)
}
+ setDisabledState (isDisabled: boolean) {
+ this.disabled = isDisabled
+ }
+
compareFn (item: SelectOptionsItem, selected: ItemSelectCheckboxValue) {
- if (typeof selected === 'string') {
+ if (typeof selected === 'string' || typeof selected === 'number') {
return item.id === selected
}