From 0e14b5b78ecf1af4f1473017c7d84b0583a05962 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 20 Jan 2026 16:26:07 +0100 Subject: đŸ’„ dating form: select2 (autocompletion) widget for period (refs #6566) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- archaeological_context_records/forms.py | 5 +++-- 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 -- cgit v1.2.3