New:
So I can get it to work withou a radio-group or withouth the right bindings. I can't get it to work with both.
This is allowed:
<div *ngFor="let column of row.controls.columns.controls; let j = index">
<ion-list radio-group [formControlName]="'col'+j">
<ion-radio></ion-radio>
</ion-list>
</div>
But then I don't have a list with a radio-group, it doesn't matter what I change it will always break. If I move the list outside it breaks, move the formControlName it breaks. I really don't know how to get this to work.
I would think that this should be the way to go:
<ion-list radio-group>
<div *ngFor="let column of columns; let j = index">
<div [formControlName]="'col'+j">
<ion-radio></ion-radio>
</div>
</div>
</ion-list>
But again the same error:
Error: No value accessor for form control with path: 'rows -> 0 -> col0'
i = the amount of rows I need. j = the amount of options/questions I need.
Old:
I am trying to use the ion-radio as a input field in a formgroup but it keeps giving me the error:
No value accessor for form control with path ...
So I switched to an input with type="radio", but if I want to group those, I need to give them the same name, which I can't because I am using a *ngFor and otherwise my formControlName is not correct anymore.
Can anybody help me to get the ion-radio to work? It would look better and easier to group.
<ion-col radio-group class="radioGroup" col-6>
<ion-col *ngFor="let column of columns; let j = index">
<input value="X" formControlName="col{{j + 1}}" type="radio" />
<!-- <ion-radio value="X"></ion-radio> -->
</ion-col>
</ion-col>
Creation:
this.inspectionTableForm = this.formBuilder.group({
header: this.formBuilder.group({
title: [this.question.properties.header[0]],
columns: this.formBuilder.array([
this.formBuilder.control('')
]),
comments: ['']
}),
rows: this.formBuilder.array([
this.initRow()
])
});
private initRow() {
// Create the temp control
let tempControl = this.formBuilder.group({
title: '',
});
// Create an array for the columns
let arr = [];
for (let index = 0; index < this.question.properties["number-of-columns"]; index++) {
// Push a control to the array and also one for the value on a higher level
arr.push(this.columns[index])
tempControl.addControl(`col${index}`, this.formBuilder.control('')) // Col-1-2-3
};
tempControl.addControl('columns', this.formBuilder.array(arr)) //Array
// Check if we need to add the comment field
if (this.question.properties["comment-field"]) {
tempControl.addControl('comment', this.formBuilder.control(''))
}
return tempControl;
}
Edit semi working new code (thanks xrobert35):
<ion-col radio-group [formControlName]="'col'+i">
<ion-item *ngFor="let column of row.controls.columns.controls">
<ion-radio></ion-radio>
</ion-item>
</ion-col>
This is what I get when I press the first option, then second and then third:
It updates the same col with some weird value. I think the problem is that I do not need i as index but j, but it breaks when I do that. Something like this:
<ion-col radio-group >
<ion-item *ngFor="let column of row.controls.columns.controls; let j = index" [formControlName]="'col'+j">
<ion-radio></ion-radio>
</ion-item>
</ion-col>
No value accessor for form control with path: 'rows -> 0 -> col0'