def dajax_load_form_assets(dajax, form, done=None, fail=None):
    """
    Dynamically loads all the scripts contained in the form media section.
    dajax -- already instanciated Dajax object
    form -- form from where to load the scripts
    done -- js actions to be executed when scripts are loaded
    fail -- js actions to be executed when scripts failed to load
    """
    if done is None:
        done = "console.log(\"form scripts loaded via ajax\");"
    if fail is None:
        fail = "alert(\"An error occured, try reloading the page.\");"

    loaders = []
    for js in form.media._js:
        loaders.append('$.ajax({{dataType: "script", cache: true, url: "{0}"}})'.format(form.media.absolute_path(js)))

    dajax.script("""
        $.when(
            {0}
        ).done(function() {{
            {1}
        }}).fail(function () {{ 
            {2}
        }});""".format(",\n".join(loaders), done, fail))

@dajaxice_register(method='POST')
def ajax_func(request, form=None)
    dajax = Dajax()
    if form is not None:
        my_form = MyForm(form)
        #do stuff with my_form
    else:
        my_form = MyForm()

    # load your form into the web page
    dajax.assign('#modalform', 'innerHTML',
                render_to_string('modalform.html',
                                {'form': my_form,
                                 'button_action': "Dajaxice.app.ajax_func(Dajax.process, { 'form': $('#my-form').serializeJSON() } ); return false;",
                                },
                                context_instance=RequestContext(request)))

    # load form's javascript assets
    dajax_load_form_assets(dajax, my_form)

    return dajax.json()