This question already has an answer here:
- How do I convert an existing callback API to promises? 20 answers
I have a widget <input type='file' style='display:none' id='foo' />
and some code that opens the dialog like this
$("#foo").click();
Now I need to set up some code so it runs after the user makes a selection and closes the dialog.
I understand that this is promise pattern but I'm not sure how to go about writing a promise. Could someone give me some guidance? It's no problem to put a change handler on the input widget but I need to code up something like this:
$("#foo").click().then(function(){
$("#theForm").submit();
});
As I understand promises the case where the postcondition is met (user selects a file and clicks OK) is called resolved and there's another name that just now eludes me for the case where the postcondition isn't met.
Those of you who are about to suggest that I do this
$("#foo").change(function(){
$("#theForm").submit();
}
I am aware of this solution but it doesn't teach me anything about writing promises.