I am trying to maintain the Back functionality. In our application, we have decided to put a back button and with the click of the back button, I have to maintain all the values of the form which a user has selected or filled. I am doing this in MVC with angularjs.
In the form, we have allowed a user to choose a color for the selected mobile model. So, the form is like the user will prompt to choose a Phone Model and then its Color and finally its Capacity. So, its a dependent fields which will be enabled only if the immediate field is selected.
The Color is created dynamically.
In my code below, which I have shared below is for the Color. After choosing the Color then I have enable the required capacities as well.
var elementName = modelName + '_Black';
var elementNameWithHash = '#' + elementName;
angular.element(elementNameWithHash).trigger("click", elementName);
modelName would be passed to it at dynamically.
The problem here lies is, the code is not executing to trigger a click for the Color section, so that it can be shown as highlighted and the below section of the capacity is enabled.
But, this code won't execute until and unless I am decorating it with setTimeout method like this:
setTimeout(function () { angular.element(elementNameWithHash).trigger("click", elementName) }, 1);
I am not able to understand why it showing this weird behavior to me.
Any light on this, would be greatly appreciated.
And, if I have to call this without setTimeout what I have to do?