Commits

Mark Lavin committed dbe91d1

Added example of submit on selection and some other docs clean up.

Comments (0)

Files changed (4)

 you must register in with django-selectable. All lookups must extend from 
 `selectable.base.LookupBase` which defines the API for every lookup.
 
-.. code-block:: python
+    .. code-block:: python
 
-    from selectable.base import LookupBase
-    from selectable.registry import registry
+        from selectable.base import LookupBase
+        from selectable.registry import registry
 
-    class MyLookup(LookupBase):
-        def get_query(self, request, term):
-            data = ['Foo', 'Bar']
-            return filter(lambda x: x.startswith(term), data)
+        class MyLookup(LookupBase):
+            def get_query(self, request, term):
+                data = ['Foo', 'Bar']
+                return filter(lambda x: x.startswith(term), data)
 
-    registry.register(MyLookup)
+        registry.register(MyLookup)
 
 
 Lookup API

docs/parameters.rst

 Each of the widgets define `update_query_parameters` which takes a dictionary. The
 most common way to use this would be in the form `__init__`.
 
-.. code-block:: python
+    .. code-block:: python
 
-    class FruitForm(forms.Form):
-        autocomplete = forms.CharField(
-            label='Type the name of a fruit (AutoCompleteWidget)',
-            widget=selectable.AutoCompleteWidget(FruitLookup),
-            required=False,
-        )
+        class FruitForm(forms.Form):
+            autocomplete = forms.CharField(
+                label='Type the name of a fruit (AutoCompleteWidget)',
+                widget=selectable.AutoCompleteWidget(FruitLookup),
+                required=False,
+            )
 
-        def __init__(self, *args, **kwargs):
-            super(FruitForm, self).__init__(*args, **kwargs)
-            self.fields['autocomplete'].widget.update_query_parameters({'foo': 'bar'})
+            def __init__(self, *args, **kwargs):
+                super(FruitForm, self).__init__(*args, **kwargs)
+                self.fields['autocomplete'].widget.update_query_parameters({'foo': 'bar'})
 
 
 .. _client-side-parameters:
 case you will need to bind a `prepareQuery` to the field. This function should accept the query dictionary. 
 You are free to make adjustments to  the query dictionary as needed.
 
-.. code-block:: html
+    .. code-block:: html
 
-    <script type="text/javascript">
-        function newParameters(query) {
-            query.foo = 'bar';
-        }
+        <script type="text/javascript">
+            function newParameters(query) {
+                query.foo = 'bar';
+            }
 
-        $(document).ready(function() {
-            $('#id_autocomplete').djselectable('option', 'prepareQuery', newParameters);
-        });
-    </script>
+            $(document).ready(function() {
+                $('#id_autocomplete').djselectable('option', 'prepareQuery', newParameters);
+            });
+        </script>
 
 
 .. _client-side-changes:
 detail you should refer to the `jQuery UI docs on these events <http://jqueryui.com/demos/autocomplete/#events>`_.
 
 
+.. _chain-select-example:
+
 Chained Selection Example
 --------------------------------------
 
 And that's it! We now have a working chained selection example. The full source
 is included in the example project.
 
+
+Sumbit On Selection Example
+--------------------------------------
+
+You might want to help your users by submitting the form once they have selected a valid
+item. To do this you simply need to listen for the `autocompleteselect` event. This
+event is fired by the text input which has an index of 0. If you field is named `my_field`
+then input to watch would be `my_field_0` such as:
+
+    .. code-block:: html
+
+        <script type="text/javascript">
+            $(document).ready(function() {
+                $(':input[name=my_field_0]').bind('autocompleteselect', function(event, ui) {
+                    $(this).parents("form").submit();
+                });
+            });
+        </script>
+

docs/releases.rst

 - Compatibility and examples for :ref:`Admin inlines <admin-inline-example>`
 - JS updated for jQuery 1.6 compatibility
 - :ref:`JS hooks <client-side-parameters>` for updating query parameters
+- :ref:`Chained selection example <chain-select-example>`
 
 
 v0.1.2

docs/settings.rst

 
 You may disable this global maximum by setting
 
-.. code-block:: python
+    .. code-block:: python
 
-    SELECTABLE_MAX_LIMIT = None
+        SELECTABLE_MAX_LIMIT = None
 
 Default: 25