Skip to content

Commit 29f1555

Browse files
committed
Changing the layout of the single-select.
1 parent 075bd41 commit 29f1555

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
<select class="form-control" [(ngModel)]="fieldValueObj.value" name="value">
2-
<option *ngFor="let item of fieldValueObj.keyValuePairList"
3-
[value]="item.key">{{item.value}}
4-
</option>
5-
</select>
1+
<ngx-select [items]="items"
2+
[formControl]="selectControl"
3+
[placeholder]="fieldValueObj.valueReadable">

eform-client/src/app/modules/cases/components/case-elements/element-singleselect/element-singleselect.component.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import {Component, Input, OnInit} from '@angular/core';
2-
import {CaseFieldValue} from 'app/models';
1+
import {Component, Input, OnDestroy, OnInit} from '@angular/core';
2+
import {CaseFieldValue, CommonDictionaryTextModel} from 'app/models';
3+
import {FormControl} from '@angular/forms';
4+
import {ISubscription} from 'rxjs/Subscription';
35

46
@Component({
57
selector: 'element-singleselect',
68
templateUrl: './element-singleselect.component.html',
79
styleUrls: ['./element-singleselect.component.css']
810
})
9-
export class ElementSingleselectComponent implements OnInit {
11+
export class ElementSingleselectComponent implements OnInit, OnDestroy {
12+
sub: ISubscription;
1013
fieldValueObj: CaseFieldValue = new CaseFieldValue();
14+
selectControl = new FormControl();
15+
items: Array<CommonDictionaryTextModel> = [];
1116

1217
@Input()
1318
get fieldValue() {
@@ -22,6 +27,23 @@ export class ElementSingleselectComponent implements OnInit {
2227
}
2328

2429
ngOnInit() {
30+
this.sub = this.selectControl.valueChanges.subscribe(value => this.onSelectedChanged(value));
31+
32+
this.fieldValueObj.keyValuePairList.forEach(function(key, value) {
33+
let kvp = new CommonDictionaryTextModel();
34+
kvp.id = key.key;
35+
kvp.text = key.value;
36+
this.push(kvp);
37+
}, this.items);
38+
}
39+
40+
41+
ngOnDestroy(): void {
42+
this.sub.unsubscribe();
43+
}
44+
45+
onSelectedChanged(value: string) {
46+
this.fieldValue.value = value;
2547
}
2648

2749
}

0 commit comments

Comments
 (0)