SQLFORM and ajax

15 views
Skip to first unread message

ga2arch(GA)

unread,
Jun 18, 2008, 5:48:36 AM6/18/08
to web2py Web Framework
How can i use SQLFORM with ajax ??

ga2arch(GA)

unread,
Jun 18, 2008, 10:29:23 AM6/18/08
to web2py Web Framework
up

Oleg

unread,
Jun 18, 2008, 10:40:22 AM6/18/08
to web2py Web Framework
you can :)

On 18 июн, 16:29, "ga2arch(GA)" <carrett...@gmail.com> wrote:
> up

Oleg

unread,
Jun 18, 2008, 10:41:23 AM6/18/08
to web2py Web Framework
but it depends what you want to do with ajax and sqlform

ga2arch(GA)

unread,
Jun 18, 2008, 11:35:33 AM6/18/08
to web2py Web Framework
simple. I want ajax form. I want that my form performs an ajax values
send

Oleg

unread,
Jun 18, 2008, 1:04:55 PM6/18/08
to web2py Web Framework
as far as I understand not with SQLFORM.. at least as it is now..
because you need, f.e. onclick=ajax(blabla) attribute for submit input
element..But you can make it with FORM.. or you can make something
like AJAXSQLFORM :) and contribute it.. Massimo will correct me, if I
am wrong :)

Massimo Di Pierro

unread,
Jun 18, 2008, 1:15:12 PM6/18/08
to web...@googlegroups.com
You can do something like this....

db.define_table('mytable',....)


def index():
    form=SQLFORM(db.mytable,_id='source')
    return dict(form=form)

def process():
    form=SQLFORM(db.mytable)
    if form.accepts(request.vars,formname=None): return 'form accepted'
    return BEAUTIFY(form.errors)

and in default/index.html

{{extend 'layout.html'}}
{{=form}}
<div id='target'></div>
<script>
      $(document).ready(function() {
          var form=getElementById('source')
          var inputs = [];
          $(':input',form).each(function() { inputs.push(this.name + '=' + escape(this.value)); });

          jQuery.ajax({

            data: inputs.join('&'),
            url: form.action,
            timeout: 2000,
            error: function() { console.log("Failed to submit"); },
            success: function(r) { getElementById('target').innerHTML=r; }
          });
          return false;
      })
</script>

Reply all
Reply to author
Forward
0 new messages