File
Metadata
selector |
tw-multiselectcb |
template |
<div [formGroup]='group'> <button style='margin-top: -30px; margin-bottom: 5px;' [ngClass]="allSelected ? 'btn-primary' : 'btn-default'" class='btn-sm btn pull-right' (click)='selectAll()' > {{field.more.allText || 'All'}}</button> <ss-multiselect-dropdown [formControlName]='field.id' [options]="options" [(ngModel)]="request[field.id]" ></ss-multiselect-dropdown> </div>
|
Methods
selectAll
|
selectAll()
|
Returns: void
|
allSelected
|
allSelected: boolean
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { Component, Input, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { FormField } from '../form-field.model'
@Component({
selector: 'tw-multiselectcb',
template: `
<div [formGroup]='group'>
<button style='margin-top: -30px; margin-bottom: 5px;' [ngClass]="allSelected ? 'btn-primary' : 'btn-default'" class='btn-sm btn pull-right' (click)='selectAll()' > {{field.more.allText || 'All'}}</button>
<ss-multiselect-dropdown [formControlName]='field.id' [options]="options" [(ngModel)]="request[field.id]" ></ss-multiselect-dropdown>
</div>
`
})
export class MultiSelectCBComponent implements OnInit {
@Input() group: FormGroup
@Input() field: FormField
@Input() request: any
ngOnInit(): void {
if (!this.field.more)
this.field.more = {}
}
get allSelected(): boolean {
return this.testSelected()
}
get options() {
if (this.field.options)
return this.field.options.map((opt: any) => {
opt.id = opt[this.field.optionValue]
opt.name = opt[this.field.optionText]
return opt
})
return []
}
selectAll(): void {
if (this.testSelected())
this.request[this.field.id] = []
else {
this.request[this.field.id] = []
this.field.options.forEach((option: any) => {
this.request[this.field.id].push(option[this.field.optionValue])
});
}
}
private testSelected(): boolean {
if (!this.request[this.field.id] || !this.field.options)
return false
if (this.request[this.field.id].length === this.field.options.length)
return true
if (this.request[this.field.id].length === this.field.options.size)
return true
return false
}
}