Why my view does not get updated properly for checkboxes but for radio buttons it is properly updated on Previous button press?

I have been trying to understand the how to refresh or update the view when new values are getting binded i tried using the modelname.refresh() and modelname.refresh(true) methods also I tried debugging through the console but I cannot find the root cause of my problem. There are lots of abindings happening but I am unable to understand it.

Here is my Problem:

I have a Questionnaire App which display various questions with answers. First question is checkbox you select two options and then click on next the next question appears which is a single choice question with radio buttons. But now when I click Previous and go to my multiple choice questions all the Options are checked but the values in abindings is proper.

I think there is something wrong with my view. And this problem doesnot occur when there is a Radio button it is appropriately displayed on Previous button click.

Below are the screenshots and code where I set my view Model and the Previous button functionality.

 setUpCurrentQuestionsModel: function(currentIndex) {
            //console.log(currentIndex);
            console.log(questionnaireStack.Question[iCurrentIndex].questionText);
            var answers = questionnaireStack.Question[iCurrentIndex].ResponseChoice;
            if (questionnaireStack.Question[iCurrentIndex].Response !== null) {
                for (var i = 0; i < answers.length; i++) {
                    answers[i].answerTyped = questionnaireStack.Question[iCurrentIndex].Response.ResponseItem[i].answerTyped; //responseItem[x] corresponds to responseChoice[x]
                }
            }

            var oCurrent = {
                index: iCurrentIndex,
                question: questionnaireStack.Question[iCurrentIndex].questionText,
                answers: answers,
                type: questionnaireStack.Question[iCurrentIndex].questionType
            };
            oCurrentQuestionModel.setData(null);
            oCurrentQuestionModel.setProperty("/", oCurrent);
        oCurrentQuestionModel.refresh(true);
        },
        goToPrevious: function(){
            alert("Previous");
            if ((iCurrentIndex === true) || (iCurrentIndex === 0) || (iCurrentIndex > 0)) {
                --iCurrentIndex;
            } else {
                iCurrentIndex = 0;
            }
            this.setUpCurrentQuestionsModel(iCurrentIndex);
        }

My View:

<List headerText="{currentQuestion>/question}" id="multipleChoices" items="{currentQuestion>/answers}">
                        <items>
                            <InputListItem label="{currentQuestion>responseText}">
                                <CheckBox select="onSelectCheck" selected="{currentQuestion>answerTyped}"/>
                            </InputListItem>
                        </items>
                    </List>
                    <List headerText="{currentQuestion>/question}" id="singleChoices" items="{currentQuestion>/answers}">
                        <items>
                            <InputListItem label="{currentQuestion>responseText}">
                                <RadioButton groupName="groupSingleChoice" selected="{currentQuestion>radioAnswerTyped}"/>
                            </InputListItem>
                        </items>
                    </List>

This is the Question 1 where I select option 1 and 3 and then click on Next

This is the 2nd Question that appears on Next
This is the 1st Question when

You can see in third picture when I go back with previous button everything is checked.

Also I tried myModelname.refresh() but it is not working. Can someway atleast hint what maybe causing this?


Why my view does not get updated properly for checkboxes but for radio buttons it is properly updated on Previous button press?
StakOverFlow
Original Source ==> Why my view does not get updated properly for checkboxes but for radio buttons it is properly updated on Previous button press?

Leave a Reply

Your email address will not be published. Required fields are marked *