Here the example about how to initialize the widget :
db.product.color.widget = lazy_options_widget(
'product_category__selected', 'product_category__unselected',
lambda category_id: (db.color.category == category_id),
request.vars.category,
orderby=db.color.id,
user_signature=True,
# If you want to process ajax requests at the time
of the object construction (not at the form rendered),
# specify your target field in the following:
field=db.product.color,
)
I am not sure what are : 'jsChangeOn','jsChangeOff',
In your widget init...
And I don't understand why you need to create a lazy_option function??
Did you install the plugin into your app and make the proper import or did
you try to just copy/paste the code provided on the web page of s-cubism??
You don't need the your function it suppose to be the lazy_option_widget
that do this task of making the ajax call and return the answer from the
database to your view and update you dropbox (html SELECT OPTIONS)...
I am puzzled a bit.
R
On Wed, Aug 29, 2012 at 12:02 PM, lyn2py <[email protected]> wrote:
> 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]> 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.
>>>
>>> --
>>>
>>>
>>>
>>>
>> --
>
>
>
>
--