Hello there! I'm currently working on enhancing an angular 1.6 app and have encountered a dilemma that needs solving. Let me provide some context: The page in question is a lengthy form consisting of thirty questions. The client-side logic includes numerous conditional statements, for example, if the user selects “Yes” on Q1, then display Q2-4, but if they choose "No" on Q1, skip to Q5. This pattern repeats throughout the extensive form.
Now, here's where things get interesting—what happens if a user mistakenly selects “Yes” on Q1, proceeds to answer Q2-4, and then decides that Q1 should actually be “No”?
So here are my two burning questions: 1) How can I effectively reset or clear the models? And 2) how do I update the view accordingly, ensuring that if they revisit Q1 choosing "Yes", Q2-Q4 are returned to their initial state?
Regarding the first issue, I've devised a simple “clearAll” method as shown below:
function clearAll(arr){
arr.forEach(function(element){
if(element!==undefined){
element = null;
}
});
}
Although this function clears the models, it falls short when it comes to updating the view. How can I ensure that Q2-4 are visually cleared/blank?
My current idea involves updating the view via:
$scope.$watch( myModel, function(val){
//set to null or delete?
}
However, I am struggling to generalize this solution to make it flexible enough to accommodate an array. Any tips or suggestions would be greatly appreciated. Thank you!