How to capture update event of Select2SingleSelectField in Turbogears?

95 Views Asked by At

There are two SingleSelectFields in a form, say Select2SingleSelectField1 and Select2SingleSelectField2. The values of both fields are retrieved from DB. The content of Select2SingleSelectField2 depends on the selected value of Select2SingleSelectField1.

In the controller how to capture the value of Select2SingleSelectField1? Could anyone help with this? Thanks.

I am using Turbogears 2.3.3 and Toscawidgets 2. There is no documentation about the parameters on Toscawidgets website. Nor is there on Turbogears website. The only piece of information is Toscawidgets 1's AutoCompleteField example http://turbogears.org/2.0/docs/main/ToscaWidgets/Cookbook/AutoComplete.html.

You can capture the event by setting the parameter completionURL.

from tw.jquery.autocomplete import AutoCompleteField

autoField = AutoCompleteField(
               id='myFieldName',
               completionURL = 'fetch_states',
               fetchJSON = True,
               minChars = 1)
1

There are 1 best solutions below

1
On

It's not totally clear to me what's your situation as you stated you are using ToscaWidgets2 but your code example relates to tw.jquery.autocomplete which was from TW1 and your single select is named "Select2SingleSelectField", which makes me think that you are actually using tw2.jqplugins.select2 which has nothing to do with tw.jquery.autocomplete as it was implemented using jQueryUI and not Select2 :)

As far as I can see tw2.jqplugins.select2 does not much apart wrapping the selection field with jQuery.select2 so the standard Select2 documentation applies as you can get a reference to the select2 from javascript and use as you normally would.

Otherwise you might want to try axf.AjaxAutoCompleteField which has little bit more documentation (not much but at least there is an example) which is still implemented on Select2.

In any case both tw2.jqplugins.select2 and axf.AjaxAutoCompleteField do not provide any particular support for depending from other fields (which in case of axf is provided by AjaxSingleSelectField) so on that part you will have to roll your own custom solution.