I have a enable/disable button for user ability. I want to add a confirmation before it gets turned on/off.
js:
function(){
I want to write a confirmation code here….
api call(url, data, method)
}
if not confirmed…
return false..and dont toggle the button…
However, in my case (intially button on) its not sending the request if not confirmed but it will toggle the button (button Off). After I refresh, it sets to previous value.. (button on)
Please help me not to toggle the switch when request is not sent when not confirming and likewise
2
Answers
Hi you can use the confirm dialogue present in JS
the confirm(…) will return true or false based on user selecting Yes or No
You can use promise to solve your problem.
Using promises ensures that the UI state is not updated until the confirmation is resolved and the API call is completed successfully.