From c04189f06df6f6cde9df6b4a68c64b3776226543 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 18 Mar 2020 16:57:51 +0100 Subject: Autocomplete widget: add "tips" message on autocomplete field --- ishtar_common/widgets.py | 58 ++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 24 deletions(-) (limited to 'ishtar_common/widgets.py') diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index d75769ffa..bf0f90a6c 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -599,13 +599,17 @@ class ModelJQueryAutocompleteField(ModelFieldMixin, forms.CharField): class JQueryAutoComplete(forms.TextInput): def __init__(self, source, associated_model=None, options=None, attrs=None, new=False, url_new='', multiple=False, limit=None, - dynamic_limit=None): + dynamic_limit=None, tips=""): """ Source can be a list containing the autocomplete values or a string containing the url used for the request. """ self.source = source self.associated_model = associated_model + if callable(tips): + self.tips = tips() + else: + self.tips = tips self.options = None if options and len(options) > 0: @@ -702,29 +706,35 @@ class JQueryAutoComplete(forms.TextInput): attrs_select['class'] += ' form-control' new = '' html = u"" - if self.new: - # WARNING: the modal for the form must be in the main template - # "extra_form_modals" list is used for that in form or view - - html = u"
" - model_name = self.associated_model._meta.object_name.lower() - limits = [] - for k in self.limit: - limits.append(k + "__" + "-".join( - [str(v) for v in self.limit[k]])) - args = [attrs_select['id']] - if limits: - args.append(';'.join(limits)) - url_new = 'new-' + model_name - if self.url_new: - url_new = self.url_new - url_new = reverse(url_new, args=args) - new = """ - - + -
- """.format(url_new, model_name, model_name) + if self.tips or self.new: + html = "
" + if self.tips: + new = """ + {} + """.format(self.tips) + if self.new: + # WARNING: the modal for the form must be in the main template + # "extra_form_modals" list is used for that in form or view + + model_name = self.associated_model._meta.object_name.lower() + limits = [] + for k in self.limit: + limits.append(k + "__" + "-".join( + [str(v) for v in self.limit[k]])) + args = [attrs_select['id']] + if limits: + args.append(';'.join(limits)) + url_new = 'new-' + model_name + if self.url_new: + url_new = self.url_new + url_new = reverse(url_new, args=args) + new += """ + + + + + """.format(url_new, model_name, model_name) + new += "
" old_value = "" if 'value' in attrs_select and attrs_select['value']: -- cgit v1.2.3