OK sure :)
MODELS
db.define_table('quotations',
Field('company_id','reference companies'),
Field('contact_id','reference contacts',
widget=lazy_options_widget('jsChangeOn','jsChangeOff',
lambda customer_id: (db.contacts.customer_id == customer_id),
trigger=request.vars.customer_id, keyword="id",
user_signature=True)
),
Field('name','string',length=255,requires=IS_NOT_EMPTY()),
)
db.companies and db.contacts are just separate tables, where each company
can have many different contacts.
CONTROLLER
def test():
form=SQLFORM(db.quotations)
# rows = db(db.contacts.customer_id==request.post_vars.id).select()
return locals()
def lazy_options():
if request.env.request_method=='POST':
rows = db(db.contacts.customer_id==request.post_vars.id).select()
return SQLTABLE(rows)
else:
return None
As I have no intentions to save the form, dbio codes has been left out.
I am using a generic view.
I made changes to the plugin to recognize the javascript onchange, so there
is no problems with detecting and making the ajax call. The ajax call goes
to a separate page "lazy_options" in the same controller.
Whenever the first field onchange is triggered, the second field will
update (expected behavior).
But the html that appears is not a SELECT field.
I use SQLTABLE(rows) because that was in the example provided. In place of
that I have tried "return rows", tried to assemble SELECT/OPTIONS on my own
to no avail.
I appreciate your help! What am I missing? Thank you :)
On Wednesday, August 29, 2012 11:06:37 PM UTC+8, Richard wrote:
>
> Can you provide :
>
> Models (for the concerned tables)
> Controller (page form concerned)
> View (of the function page)
>
> It will be easier to help.
>
> Richard
>
> On Wed, Aug 29, 2012 at 10:56 AM, lyn2py <[email protected]
> <javascript:>>wrote:
>
>> Yes that is the internal code.
>>
>> I don't understand the example given. I have tested it but I don't know
>> what I'm missing.
>>
>> My setup is also different than the example given in their website.
>>
>> My current and only bottleneck is what value to return to the ajax call.
>> I have tried SQLTABLE(rows), SELECT, rows, XML versions and none could
>> produce a select field with the filtered options.
>>
>> Please help, I am out of ideas.
>>
>> --
>>
>>
>>
>>
>
--