diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-03-18 16:57:51 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-03-18 16:57:51 +0100 |
commit | c04189f06df6f6cde9df6b4a68c64b3776226543 (patch) | |
tree | 0c711e3f3404775e6da7e35745e0575b6e251936 /ishtar_common/widgets.py | |
parent | 64f971f0546b051e4d38ac8418e689df1f1ff6a5 (diff) | |
download | Ishtar-c04189f06df6f6cde9df6b4a68c64b3776226543.tar.bz2 Ishtar-c04189f06df6f6cde9df6b4a68c64b3776226543.zip |
Autocomplete widget: add "tips" message on autocomplete field
Diffstat (limited to 'ishtar_common/widgets.py')
-rw-r--r-- | ishtar_common/widgets.py | 58 |
1 files changed, 34 insertions, 24 deletions
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"<div class='input-group'>" - 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 = """ - <span class="input-group-append"> - <a href="#" class="add-button input-group-text" - onclick="dt_qa_open('{}', 'modal-dynamic-form-{}');">+</a> - </span></div> - """.format(url_new, model_name, model_name) + if self.tips or self.new: + html = "<div class='input-group'>" + if self.tips: + new = """<span class="input-group-append"> + <span class="add-button input-group-text"><em>{}</em></span></span> + """.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 += """ + <span class="input-group-append"> + <a href="#" class="add-button input-group-text" + onclick="dt_qa_open('{}', 'modal-dynamic-form-{}');">+</a> + </span> + """.format(url_new, model_name, model_name) + new += "</div>" old_value = "" if 'value' in attrs_select and attrs_select['value']: |