ajax - sqlform

33 views
Skip to first unread message

Dirk C

unread,
Oct 21, 2019, 2:02:35 AM10/21/19
to web2py-users
Hey,

I'm new to web2py.
I want to update a inputfield with the return value of a function.
when adding a new record to t_cre_customers, i want to lookup in table t_cre_contractors.
I'm using focusout event to launch.
Passing the argument of field t_cre_customers_f_ctm_no to function cre_find_contractor() does not work.
And return the result to the sqlform in field t_cre_customers_f_ctm_cr_atv_cd neither.
Thanks voor any help.

db

########################################
# TABLE : t_cre_contractors
########################################
db.define_table('t_cre_contractors',
    Field('f_ctt_no', type='string',
          label=T('Contractant number'),length=8),
    Field('f_ctt_cr_atv_cd', type='string',
          label=T('Credit activity code contractant'),length=8)
)

########################################
# TABLE : t_cre_customers
########################################
db.define_table('t_cre_customers',
    Field('f_ctm_no', type='string',
          label=T('Contractant number borrower'),length=8),
    Field('f_ctm_nm', type='string',
          label=T('Name borrower'),length=50),
    Field('f_ctm_cr_atv_cd', type='string',
          label=T('Credit activity code borrower'),length=8),
    auth.signature,
    format='%(f_ctm_nm)s'
)
db.t_cre_customers.f_ctm_no.requires=[IS_NOT_EMPTY()]
db.t_cre_customers.f_ctm_nm.requires=[IS_NOT_EMPTY()]


controler
# add customer
def cre_customer_add():
    form_add_customer = SQLFORM(db.t_cre_customers)
    if form_add_customer.process().accepted:
        response.flash = 'You have successfully submitted the form'
    elif form_add_customer.errors:
        response.flash = 'Please check your form for errors'
    else:
        response.flash = 'Please fill all fields!'
    return dict(form_add_customer=form_add_customer)

#find customer in table t_cre_contractors
def cre_find_contractor():
    waarde = request.args(0)
    response.flash = waarde
    return "test"

view
{{extend 'layout.html'}}
<h1>Add customer</h1>
<br/>
<br/>
{{=form_add_customer}}
<script>
    jQuery(document).ready(function(){
        jQuery('#t_cre_customers_f_ctm_cr_atv_cd__row').show();
});
    jQuery('#t_cre_customers_f_ctm_no').focusout(function(){
        jQuery('#t_cre_customers_f_ctm_cr_atv_cd__row').show();
        ajax('{{=URL('default','cre_find_contractor')}}','t_cre_customers_f_ctm_no','t_cre_customers_f_ctm_cr_atv_cd');
});
</script>
Reply all
Reply to author
Forward
0 new messages