Use Case and Perfect Example for Deferred Objects and Promises


Problem Statement

You’ve a Master Form containing multiple child forms.

Issue is, child forms are submittable on their own. But master form can only be submitted if all inner forms are valid and submitted.

Again, we’ve all separate services for childforms and master form – Meaning, child forms 1,2 & 3 have api1, api2 and api3 as services (say). Master has api-master which can’t accept submissions from child forms but it is dependent on their successful submission as the backend requires data from all of them.

Multiple child forms with in a Master Form Multiple child forms with in a Master Form

Solution Approach

A formcan contain only one actionpath and therefore nested forms are not possible in HTML. The only way (that I can think of and) I believe to be efficient is submitting via Ajax.

Nested Ajax Calls

One approach is that we use nested ajax calls. They look like

    $.ajax3({ ... })

View original post 407 more words