Skip to content

Commit

Permalink
apps: Use the existing select2 implementation were appropriate (widge…
Browse files Browse the repository at this point in the history
…t and js)

This makes us use more fancy dropdowns - it looks like that's how these dropdowns
should (or used to) look like - before something broke or so.
  • Loading branch information
rmader authored and philli-m committed May 20, 2020
1 parent 27094f3 commit 08d38b8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
7 changes: 4 additions & 3 deletions meinberlin/apps/mapideas/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from adhocracy4.labels.mixins import LabelsAddableFieldMixin
from adhocracy4.maps import widgets as maps_widgets
from meinberlin.apps.contrib.mixins import ImageRightOfUseMixin
from meinberlin.apps.contrib.widgets import Select2Widget

from . import models

Expand All @@ -21,13 +22,13 @@ def __init__(self, *args, **kwargs):
self.fields['point'].error_messages['required'] = _(
'Please locate your proposal on the map.')

class Media:
js = ('select_dropdown_init.js',)

class Meta:
model = models.MapIdea
fields = ['name', 'description', 'image', 'category',
'labels', 'point', 'point_label']
widgets = {
'category': Select2Widget,
}


class MapIdeaModerateForm(forms.ModelForm):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<span class="form-hint">
{% trans 'You can choose a preset for further customization.' %}
</span>
<select id="select_{{ name }}">
<select id="select_{{ name }}" class="js-select2">
<option value="">---</option>
{% for preset in presets_uncategorized %}
<option value="{{ preset.polygon }}">{{ preset.name }}</option>
Expand Down
4 changes: 4 additions & 0 deletions meinberlin/apps/plans/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from adhocracy4.dashboard.components.forms import ProjectDashboardForm
from adhocracy4.maps import widgets as maps_widgets
from adhocracy4.projects import models as project_models
from meinberlin.apps.contrib.widgets import Select2Widget

from . import models

Expand Down Expand Up @@ -67,6 +68,9 @@ class Meta:
model = project_models.Project
fields = ['plans']
required = False
widgets = {
'plans': Select2Widget,
}

def save(self, commit=False):
plans = self.cleaned_data['plans']
Expand Down
2 changes: 2 additions & 0 deletions meinberlin/apps/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from adhocracy4.dashboard.forms import ProjectDashboardForm
from adhocracy4.maps import widgets as maps_widgets
from adhocracy4.projects.models import Project
from meinberlin.apps.contrib.widgets import Select2Widget
from meinberlin.apps.users import fields as user_fields

from .models import ModeratorInvite
Expand Down Expand Up @@ -89,6 +90,7 @@ class Meta:
fields = ['administrative_district', 'point']
required_for_project_publish = []
widgets = {
'administrative_district': Select2Widget,
'point': maps_widgets.MapChoosePointWidget(
polygon=settings.BERLIN_POLYGON)
}
Expand Down

0 comments on commit 08d38b8

Please sign in to comment.