Checkbox showing previous value


#1

Hi, I am building a new app.

I am showing form in the loop. On next, I reset the value of the current item, the value is reset but the checkbox is still showing previous value. Data for the checkbox is almost the same.

HTML code :

<ion-content *ngIf="!preview " >
<div style=“margin-top:5%;” text-wrap >
<ion-label *ngIf=“form && form.sections[sectionNo].title” stacked style=“padding-left: 10px;font-size:15px;” text-center>{{form.sections[sectionNo].title| uppercase}}</ion-label>

<ion-list radio-group *ngIf="form.sections[sectionNo].type=='select'" [(ngModel)]="form.sections[sectionNo].response" (ngModelChange) = "nextField()">
  <ion-item *ngFor="let option of form.sections[sectionNo].data" >
    <ion-label>{{option | uppercase}}</ion-label>
    <ion-radio name="radio" [value]="option"></ion-radio>
  </ion-item>
</ion-list>

</div>
</ion-content>

TS file :

nextField() {
if(this.form.sections[this.sectionNo].response){
this.saveData(this.form.sections[this.sectionNo].response, this.sectionNo);
if(this.sectionNo < this.maxSections){
this.sectionNo ++;
this.form.sections[this.sectionNo].response = “”;
}
else{
if(this.screen) this.submitForm();
else this.preview = true;
}
}
else alert(“Please Select Value”);
}

Sample Data Format :

“sections”: [
{
“filename”: “front”,
“required”: “true”,
“data”: [
“Intact”,
“Scratched”,
“Dented”,
“Missing”
],
“type”: “select”,
“title”: “Hub”,
“response”: null
},
{
“required”: “true”,
“data”: [
“Intact”,
“Scratched”,
“Dented”,
“Missing”
],
“filename”: “front”,
“type”: “select”,
“title”: “Handle”,
“response”: null
},
{
“required”: “true”,
“data”: [
“Intact”,
“Scratched”,
“Dented”,
“Missing”
],
“filename”: “front”,
“type”: “select”,
“title”: “Speedometer”,
“response”: null
},
{
“required”: “true”,
“data”: [
“Intact”,
“Scratched”,
“Dented”,
“Missing”
],
“filename”: “left”,
“type”: “select”,
“title”: “Left Cover”,
“response”: null
},
{
“required”: “true”,
“data”: [
“Intact”,
“Scratched”,
“Dented”,
“Missing”
],
“filename”: “right”,
“type”: “select”,
“title”: “Right Cover”,
“response”: null
}
]

Code is working and data is coming correctly but in the preview, checkbox shows previously selected value while the value is nul.
Please help


#2

I use a WCF service for a backend. The way that I handle the ability to display null values is to add an object that represents a null value to the collection that populates the select.

You might be able to use null, I have to use 0 because of the handling of integer values in .net.


#3

thanks, but it is not working still checkbox is coming checked on previous value


#4

It looks like you are binding the value property to the entire object as opposed to a value!


#5

Sorry, i didn’t get it. Can you explain more about it? I am new to this.


#6

I am sorry for my last answer, I had not had enough coffee.

Let me get my machine fired up and I will post some code from my project.