doug_warren committed 01ecda3

Adding autosubmit to widgets

Comments (0)

Files changed (3)

 Basic widget for auto-completing text. The widget returns the item value as defined
 by the lookup `get_item_value`. If the `allow_new` keyword argument is passed as
-true it will allow the user to type any text they wish.
+true it will allow the user to type any text they wish.  If the `autosubmit` keyword
+argument is passed as true, it will submit the form upon any value being selected.
 .. _AutoComboboxWidget:


         self.allow_new = kwargs.pop('allow_new', False)
         self.qs = {}
         self.limit = kwargs.pop('limit', None)
+        self.autosubmit = kwargs.pop('autosubmit', False)
         super(AutoCompleteWidget, self).__init__(*args, **kwargs)
     def update_query_parameters(self, qs_dict):
             self.qs['limit'] = self.limit
         if self.qs:
             url = '%s?%s' % (url, urlencode(self.qs))
+        if self.autosubmit:
+            attrs[u'data-autosubmit'] = True
         attrs[u'data-selectable-url'] = url
         attrs[u'data-selectable-type'] = 'text'
         attrs[u'data-selectable-allow-new'] = str(self.allow_new).lower()


                             return false;
+                    if($(input).data("autosubmit"))
+                    {
+                        $(input).parents("form").submit();
+                    }
             }).addClass("ui-widget ui-widget-content ui-corner-all");
             $(input).data("autocomplete")._renderItem = function(ul, item) {