Commit 32f4edb3 authored by PJ Janse van Rensburg's avatar PJ Janse van Rensburg

Merge branch 'ajax-min-input-length'

parents 9264a987 ab23b6c5
......@@ -6,6 +6,7 @@ next release
* Sort on multiple columns with `column_default_sort`
* Upgrade Leaflet and Leaflet.draw plugins, used for geoalchemy integration
* Specify `minimum_input_length` for ajax widget
1.5.2
-----
......
......@@ -130,8 +130,11 @@ class PostAdmin(sqla.ModelView):
'fields': (User.username, User.email)
},
'tags': {
'fields': (Tag.name,)
}
'fields': (Tag.name,),
'minimum_input_length': 0,
'placeholder': 'Please select',
'page_size': 5,
},
}
def __init__(self, session):
......
......@@ -50,6 +50,7 @@ class QueryAjaxModelLoader(AjaxModelLoader):
def get_list(self, term, offset=0, limit=DEFAULT_PAGE_SIZE):
query = self.model.objects
if len(term) > 0:
criteria = None
for field in self._cached_fields:
......
......@@ -52,6 +52,7 @@ class QueryAjaxModelLoader(AjaxModelLoader):
def get_list(self, term, offset=0, limit=DEFAULT_PAGE_SIZE):
query = self.model.select()
if len(term) > 0:
stmt = None
for field in self._cached_fields:
q = field ** (u'%%%s%%' % term)
......
......@@ -671,7 +671,9 @@ class BaseModelView(BaseView, ActionsMixin):
form_ajax_refs = {
'user': {
'fields': ('first_name', 'last_name', 'email'),
'page_size': 10
'placeholder': 'Please select',
'page_size': 10,
'minimum_input_length': 0,
}
}
......
......@@ -61,6 +61,9 @@ class AjaxSelect2Widget(object):
placeholder = field.loader.options.get('placeholder', gettext('Please select model'))
kwargs.setdefault('data-placeholder', placeholder)
minimum_input_length = int(field.loader.options.get('minimum_input_length', 1))
kwargs.setdefault('data-minimum-input-length', minimum_input_length)
return HTMLString('<input %s>' % html_params(name=field.name, **kwargs))
......
......@@ -11,7 +11,7 @@
var opts = {
width: 'resolve',
minimumInputLength: 1,
minimumInputLength: $el.attr('data-minimum-input-length'),
placeholder: 'data-placeholder',
ajax: {
url: $el.attr('data-url'),
......@@ -305,6 +305,8 @@
if ($el.attr('data-allow-blank'))
opts['allowClear'] = true;
opts['minimumInputLength'] = $el.attr('data-minimum-input-length');
if ($el.attr('data-tags')) {
$.extend(opts, {
tokenSeparators: [','],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment