Reputation: 301
I have got a formgroup named input form, having an formarray of topics. I want to change the value of an inputfield using a dynamically created filtered list.
the filter function works fine:
filtertopic(idx: number) {
const test = this.topics.value[idx].topic;
if (test !== "") {
this.onderdeel = "topics";
this.queryselector = idx;
this.filteredList = this.Topics.filter(function(el) {
return el.toLowerCase().indexOf(test.toLowerCase()) >-1;
}.bind(this));
} else { this.filteredList = [];
}
}
but the function handleBlur to change the value in the input field does not work
handleBlur() {
console.log(this.selectedIdx);
if (this.selectedIdx > -1) {
if (this.onderdeel =="topics") {
this.topics.value[this.queryselector].topic.setValue(this.filteredList[this.selectedIdx]);
} else {
this.query = this.filteredList[this.selectedIdx];
}
}
this.filteredList = [];
this.selectedIdx = -1;
}
I think it has to do with the
this.topics.value[this.queryselector].topic.setValue(this.filteredList[this.selectedIdx]);
to set the formcontrol value. Does anybody know the solution?
Upvotes: 3
Views: 11583
Reputation: 385
this.yourdataobject.forEach(task => {
this.formcontrolname.push(
this.fb.group({
name: [task.name, Validators.required]
})
);
});
Upvotes: 2