Commit cc40c6de authored by PJ Janse van Rensburg's avatar PJ Janse van Rensburg

Merge branch 'master' of https://github.com/sealemar/flask-admin into ajax-min-input-length

parents 9264a987 fba873d5
...@@ -50,6 +50,7 @@ class QueryAjaxModelLoader(AjaxModelLoader): ...@@ -50,6 +50,7 @@ class QueryAjaxModelLoader(AjaxModelLoader):
def get_list(self, term, offset=0, limit=DEFAULT_PAGE_SIZE): def get_list(self, term, offset=0, limit=DEFAULT_PAGE_SIZE):
query = self.model.objects query = self.model.objects
if len(term) > 0:
criteria = None criteria = None
for field in self._cached_fields: for field in self._cached_fields:
......
...@@ -52,6 +52,7 @@ class QueryAjaxModelLoader(AjaxModelLoader): ...@@ -52,6 +52,7 @@ class QueryAjaxModelLoader(AjaxModelLoader):
def get_list(self, term, offset=0, limit=DEFAULT_PAGE_SIZE): def get_list(self, term, offset=0, limit=DEFAULT_PAGE_SIZE):
query = self.model.select() query = self.model.select()
if len(term) > 0:
stmt = None stmt = None
for field in self._cached_fields: for field in self._cached_fields:
q = field ** (u'%%%s%%' % term) q = field ** (u'%%%s%%' % term)
......
...@@ -61,6 +61,9 @@ class AjaxSelect2Widget(object): ...@@ -61,6 +61,9 @@ class AjaxSelect2Widget(object):
placeholder = field.loader.options.get('placeholder', gettext('Please select model')) placeholder = field.loader.options.get('placeholder', gettext('Please select model'))
kwargs.setdefault('data-placeholder', placeholder) 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)) return HTMLString('<input %s>' % html_params(name=field.name, **kwargs))
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
var opts = { var opts = {
width: 'resolve', width: 'resolve',
minimumInputLength: 1, minimumInputLength: $el.attr('data-minimum-input-length'),
placeholder: 'data-placeholder', placeholder: 'data-placeholder',
ajax: { ajax: {
url: $el.attr('data-url'), url: $el.attr('data-url'),
...@@ -305,6 +305,8 @@ ...@@ -305,6 +305,8 @@
if ($el.attr('data-allow-blank')) if ($el.attr('data-allow-blank'))
opts['allowClear'] = true; opts['allowClear'] = true;
opts['minimumInputLength'] = $el.attr('data-minimum-input-length');
if ($el.attr('data-tags')) { if ($el.attr('data-tags')) {
$.extend(opts, { $.extend(opts, {
tokenSeparators: [','], 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