diff --git a/src/agenda_culturel/forms.py b/src/agenda_culturel/forms.py index 7efe4c8..af3b97b 100644 --- a/src/agenda_culturel/forms.py +++ b/src/agenda_culturel/forms.py @@ -90,6 +90,15 @@ class CategorisationRuleImportForm(ModelForm): class EventForm(ModelForm): old_local_image = CharField(widget=HiddenInput(), required=False) + tags = MultipleChoiceField( + label=_("Tags"), + initial=None, + choices=[], + help_text=_('Optional. If you offer labels, they''ll make it easier for your girlfriends to find your event.'), + required=False + ) + + class Meta: model = Event exclude = [ @@ -119,7 +128,6 @@ class EventForm(ModelForm): "other_versions": HiddenInput(), "uuids": MultipleHiddenInput(), "reference_urls": DynamicArrayWidgetURLs(), - "tags": DynamicArrayWidgetTags(), } def __init__(self, *args, **kwargs): @@ -131,6 +139,7 @@ class EventForm(ModelForm): self.fields['category'].queryset = self.fields['category'].queryset.order_by('name') self.fields['category'].empty_label = None self.fields['category'].initial = Category.get_default_category() + self.fields['tags'].choices = Tag.get_tag_groups(all=True) def is_clone_from_url(self): return self.cloning diff --git a/src/agenda_culturel/templates/agenda_culturel/event_form.html b/src/agenda_culturel/templates/agenda_culturel/event_form.html index ed5db02..a43cd20 100644 --- a/src/agenda_culturel/templates/agenda_culturel/event_form.html +++ b/src/agenda_culturel/templates/agenda_culturel/event_form.html @@ -82,5 +82,33 @@ Création d'une copie de {% else %} const element = document.querySelector('#id_exact_location'); const choices = new Choices(element); + show_firstgroup = { + choice(classes, choice) { + const i = Choices.defaults.templates.choice.call(this, classes, choice); + if (this.first_group !== null && choice.groupId == this.first_group) + i.classList.add("visible"); + return i; + }, + choiceGroup(classes, group) { + const g = Choices.defaults.templates.choiceGroup.call(this, classes, group); + if (this.first_group === undefined && group.value == "Suggestions") + this.first_group = group.id; + if (this.first_group !== null && group.id == this.first_group) + g.classList.add("visible"); + return g; + } + }; + const tags = document.querySelector('#id_tags'); + const choices_tags = new Choices(tags, + { + placeholderValue: 'Sélectionner les étiquettes à ajouter', + allowHTML: true, + delimiter: ',', + removeItemButton: true, + shouldSort: false, + callbackOnCreateTemplates: () => (show_firstgroup) + } + ); + {% endblock %} \ No newline at end of file