Dropdown foreign bug fixes

This commit is contained in:
Sebastian Seedorf
2017-06-09 16:44:58 +02:00
parent cc49a89ea4
commit 37eb1e37ee
6 changed files with 147 additions and 137 deletions

View File

@@ -43,5 +43,6 @@ export class AppComponent {
public submit(value: any) {
console.log('send', value);
this.valueService.postValues(this.uri, value, (data, err) => console.log("posted", data, err));
}
}

View File

@@ -26,7 +26,6 @@ export class DynFormComponent implements OnChanges {
private form: FormGroup;
public ngOnChanges(changes: SimpleChanges) {
console.log("changes form", changes);
if (changes['questions']) {
let controls = {};
for(let i = 0; this.questions && i < this.questions.length; i++) {

View File

@@ -6,9 +6,9 @@ import {CustomInputComponent} from "./custom-input.component";
selector: 'checkbox-input',
template:
`
<label *ngIf="!readonly"><input type="radio" [checked]="value===true" (change)="onChange(true)">Yes</label><br/>
<label *ngIf="!readonly"><input type="radio" [checked]="value===false" (change)="onChange(false)">No</label><br/>
<label *ngIf="!readonly && nullable"><input type="radio" [checked]="value===null" (change)="onChange(null)">N/A</label><br/>
<label *ngIf="!readonly"><input type="radio" [checked]="value===true" (change)="onChange(true)">Yes</label><br *ngIf="!readonly"/>
<label *ngIf="!readonly"><input type="radio" [checked]="value===false" (change)="onChange(false)">No</label><br *ngIf="!readonly"/>
<label *ngIf="!readonly && nullable"><input type="radio" [checked]="value===null" (change)="onChange(null)">N/A</label>
<span *ngIf="readonly">{{value ? "Yes" : (value===false ? "No" : "N/A")}}</span>
`,
providers: [

View File

@@ -2,7 +2,6 @@ import {Component, forwardRef, Input, OnChanges, SimpleChanges} from '@angular/c
import { NG_VALUE_ACCESSOR, NG_VALIDATORS, FormControl, ValidationErrors } from '@angular/forms';
import {CustomInputComponent} from "./custom-input.component";
import {ValueService} from '../services/value.service';
import {consoleTestResultHandler} from 'tslint/lib/test';
@Component({
selector: 'dropdown-input',
@@ -34,6 +33,7 @@ export class DropdownInputComponent extends CustomInputComponent implements OnCh
@Input() foreign: {uri: string, keys: string, values: string, options?: {key: string, value: string}[]};
private listedItems: Array<{key: string, value: string}> = [];
private foreignItems: Array<{key: string, value: string}> = [];
private pendingForeign: boolean = false;
private constVal: string;
constructor(private valueService: ValueService) {
@@ -43,6 +43,7 @@ export class DropdownInputComponent extends CustomInputComponent implements OnCh
// set initial value
public writeValue(obj: any): void {
this.value = obj;
console.log("write", this.value);
this.updateConst();
}
@@ -51,12 +52,24 @@ export class DropdownInputComponent extends CustomInputComponent implements OnCh
this.setListedItems();
}
if (changes['foreign'] && this.foreign) {
this.pendingForeign = true;
this.valueService.getValues(this.foreign.uri, {}, (res, err) => {
this.foreignItems = [];
for (let item of res as any) {
this.foreignItems.push({key: item[this.foreign.keys], value: item[this.foreign.values]});
}
this.setListedItems();
setTimeout(() => {
const val = this.value;
this.value = "UNLIKY_VLAUEdrtwe53wrsdsfrsr3drw34rerw3raxdwgxcjlb234r";
setTimeout(() => {
this.value = val;
this.change(false);
this.pendingForeign = false;
console.log("after timeout", this.value);
}, 0);
}, 0);
});
}
}
@@ -66,6 +79,7 @@ export class DropdownInputComponent extends CustomInputComponent implements OnCh
this.listedItems = [{key: "", value: "N/A"}, {key: null, value: "N/A"}].concat(this.items || []).concat(this.foreignItems || []);
else
this.listedItems = [].concat(this.items || []).concat(this.foreignItems || []);
console.log(this.listedItems, this.value);
this.updateConst();
}
@@ -82,6 +96,7 @@ export class DropdownInputComponent extends CustomInputComponent implements OnCh
// validates the form, returns null when valid else the validation object
public validate(c: FormControl): ValidationErrors {
console.log(this.initComplete, this.value, this.listedItems);
if (!this.initComplete)
return null;
if (this.value===null) {
@@ -103,8 +118,15 @@ export class DropdownInputComponent extends CustomInputComponent implements OnCh
// on button click
protected onChange(value: any): boolean {
this.value = value;
console.log("change", this.value);
super.change();
this.change();
return false;
}
protected touch() {
console.log("hehehe", this.pendingForeign);
if (!this.pendingForeign)
super.touch();
}
}

View File

@@ -47,7 +47,6 @@ export class TagInputComponent extends CustomInputComponent {
this.value[key] = (this.nullable ? null : false);
}
}
console.log("writeValue", isUpdated, this.value);
if (isUpdated) {
setTimeout(() => this.change(true), 0);