Is This Even Possible: Serve Form Via Ajax

59 views
Skip to first unread message

Mark Billion

unread,
Oct 7, 2015, 2:01:56 PM10/7/15
to web2py-users
****** Splits the input "name" attribute up => generates a query => creates sqlform => returns form
def ajax_form_creator():
    for k,v in request.vars.iteritems():
        field_array = k.split('-')

        this_page_form = db[field_array[3]].id==field_array[1]
        db[field_array[3]].client.requires=IS_IN_DB(db(db.client.id == x), 
                                                    "client.id", '%(d_ln)s, %(d_fn)s')
        db[field_array[3]].client.default = x    
        
        ajax_form = SQLFORM(db[field_array[3]], this_page_form, deletable=True).process()
        ajax_form['_id']="Ajax_Form"
        return ajax_form


******  Button triggers the above script on click.  The result, the ajax_form, should be sent to the target div         
<form>
   <input name="1-2-street_1-client_address" type="button" onclick="ajax('{{=URL('default', 'ajax_form_creator')}}', [$(this).attr('name')], 'target')" />
</form>
<div id="target"></div>

******

Nothing loads in the target div despite the fact that I know the connection works (i.e., I can get it to load other data into the target).  Should I serialize the SQLFORM object?  If so, how?  Any thoughts are greatly appreciated.

Vinicius Assef

unread,
Oct 7, 2015, 8:54:45 PM10/7/15
to web2py
Your action (function ajax_form_creator) should return a dict.

What it returns if you type the url direct in your browser address field?

--
Vinicius Assef
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages