Skip to content

Commit b2458fd

Browse files
authored
Merge pull request #83 from Gid733/master
Added entity-select functionality
2 parents a73f2b1 + e6f0ab1 commit b2458fd

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<select class="form-control" [(ngModel)]="fieldValueObj.value" name="value" disabled>
2-
<option [value]="fieldValueObj.value">{{fieldValueObj.valueReadable}}
3-
</option>
4-
</select>
1+
<ngx-select [items]="items"
2+
[formControl]="selectControl"
3+
[placeholder]="fieldValueObj.valueReadable">

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

Lines changed: 20 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 {ISubscription} from 'rxjs/Subscription';
4+
import {FormControl} from '@angular/forms';
35

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

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

2429
ngOnInit() {
30+
this.sub = this.selectControl.valueChanges.subscribe(value => this.onSelectedChanged(value));
31+
for (const keyValuePair of this.fieldValueObj.keyValuePairList) {
32+
this.items.push({id: keyValuePair.key, text: keyValuePair.value});
33+
}
34+
}
35+
36+
ngOnDestroy(): void {
37+
this.sub.unsubscribe();
38+
}
39+
40+
onSelectedChanged(value: string) {
41+
this.fieldValue.value = value;
2542
}
2643

2744
}

0 commit comments

Comments
 (0)