Is it possible to make a form field depend on another form field without submiting the form?

52 views
Skip to first unread message

João Matos

unread,
Mar 14, 2019, 2:28:02 PM3/14/19
to web2py-users
Hello,

Is it possible to make a form field depend on another form field without submiting the form?

Thanks,

JM

Leonel Câmara

unread,
Mar 14, 2019, 8:11:19 PM3/14/19
to web2py-users

João Matos

unread,
Mar 15, 2019, 5:34:20 AM3/15/19
to web2py-users
Sorry. I didn't explain myself correctly.
What I meant was depend one field values (db search) depend on another field value.
Something like this pseudo code:

if form client_id:
  form.invoices = db(db.invoice(client_id == form.client_id)).select()

Is this possible without submitting the form?

Leonel Câmara

unread,
Mar 15, 2019, 6:44:53 AM3/15/19
to web2py-users
Like a computed value? I don't think I'm understanding. What exactly are you trying to do?

João Matos

unread,
Mar 15, 2019, 6:59:28 AM3/15/19
to web2py-users
I want the values shown in field form.invoices to be loaded from a db query (that uses the value of form.client_id) but only after the user selects the form.client_id and before the form is submited.
Is this possible?

Leonel Câmara

unread,
Mar 15, 2019, 7:29:45 AM3/15/19
to web2py-users
It's possible but you need to use ajax to change the options in the invoices field. Basically you need to listen for change in client_id and when that happens you fire an ajax call and ask web2py for the new options and put them in the invoices field.

Leonel Câmara

unread,
Mar 15, 2019, 7:34:09 AM3/15/19
to web2py-users
Here's an example I made long ago, I would do things differently nowadays but it shows how it can be done.

João Matos

unread,
Mar 17, 2019, 1:04:27 PM3/17/19
to web2py-users
I'll check it out in the next days, thanks.
Reply all
Reply to author
Forward
0 new messages