javascript - Is there a way to get jQuery's .on() functions to play nice with promises? -
Stay with me - I know what I am doing down is stupid, I'm not just online solution for UN You can see yourself:
I have the following work, which I promise:
function getInput () {var form = $ ("form .prompt "); // Some form in the DOM, it is promising returns properly. Promise.resolve (form.show) focus (). Submit (function (event) {var input = $ (this). Find ("input"); var InputVal = input.val (); Warning ("form submitted input input is" + input veal); event. PreventDefault (); resolution (inputVal);})); }
I call that function and try to wait for the promise to resolve it:
getInput () Then (function (feedback) {warning ("input is solved; response is" + response););
I want to see the following practices: There is no alert until I submit the form, after which I will see "form submit"! And then "input solved".
Instead, I see an "input solution" immediately. (Obviously, after this, once I submit the form, I see "form submit!")
I think I am completely. I am not performing the Submit () function properly; I am treating it as if it is right, and promise will be done. Obviously, this is not happening, I gather it. There are some other values or properties in the submission () and Promos.Rollway () is ending its promise rating chain so far, this is the reason that immediate () is executed immediately.
Besides, I know I'm handling. Submit () such as this is a single event I'm waiting on while it is a callback function that presents every time form.
My question is what am I trying to do. Which is, some code execution suspended ("input solved" is presented here by alert) until a particular form is submitted once? It seems like I need a function, which is loop with a short time-duration until it sees that a flag is there. Submit () is set by callback ...
You can do it completely. It may look like this:
function getInput () {new promise (work (solution, reject) {var $ form = $ ("form.prompt"). ('Submit' Function (event) {var input = $ form.find ("input") .val (); event.preventDefault (); resolution (input);});}); } GetInput () Then (action (response) {warning ("input is solved; response is" + response););
But this example completely shows that the action is not the right tool for the task: you can solve it once or reject it.
Comments
Post a Comment