diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2026-01-20 16:26:07 +0100 |
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2026-01-20 17:28:08 +0100 |
| commit | 0e14b5b78ecf1af4f1473017c7d84b0583a05962 (patch) | |
| tree | 00945ffabad8b49b4f0ef64849a748f259fc5a92 | |
| parent | ef281a21d74ef694a9bfb92fc3f61ce744af5f2a (diff) | |
| download | Ishtar-0e14b5b78ecf1af4f1473017c7d84b0583a05962.tar.bz2 Ishtar-0e14b5b78ecf1af4f1473017c7d84b0583a05962.zip | |
💄 dating form: select2 (autocompletion) widget for period (refs #6566)
| -rw-r--r-- | archaeological_context_records/forms.py | 5 | ||||
| -rw-r--r-- | ishtar_common/widgets.py | 11 |
2 files changed, 13 insertions, 3 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index a65aad717..42c76a9ad 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -912,8 +912,9 @@ class QADating(ManageOldType, forms.Form): label=_("Reference"), validators=[validators.MaxLengthValidator(400)], required=False ) - period_id = forms.ChoiceField(label=_("Chronological period"), choices=[], - required=False) + period_id = widgets.Select2SimpleField( + label=_("Period"), required=False, modal="modal-dynamic-form" + ) start_date = forms.IntegerField(label=_("Start date"), required=False) end_date = forms.IntegerField(label=_("End date"), required=False) quality_id = forms.ChoiceField(label=_("Quality"), required=False, choices=[]) diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index 85a1d20b1..d4c9d625d 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -311,6 +311,13 @@ class Select2Base(Select2Media): except (self.model.DoesNotExist, ValueError): # an old reference? it should not happen pass + if attrs.get("modal", None): + if options: + options = options[:-1] + ", " + else: + options = "{" + modal = attrs['modal'] + options += f" dropdownParent: $('#{modal}')}}" if attrs.get("full-width", None): if options: options = options[:-1] + ", " @@ -401,6 +408,8 @@ class Select2BaseField(object): widget = Select2Multiple else: widget = Select2Simple + if "modal" in kwargs: + attrs["modal"] = kwargs.pop("modal") if kwargs.get("style", None): attrs["style"] = kwargs.pop("style") kwargs["widget"] = widget( @@ -410,7 +419,7 @@ class Select2BaseField(object): new=new, attrs=attrs, ) - super(Select2BaseField, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def get_q(self): q = self.model.objects |
