Skip to content

Commit

Permalink
Merge pull request #95 from CentreForDigitalHumanities/feature/js-sea…
Browse files Browse the repository at this point in the history
…rch-widget

Feature/js search widget
  • Loading branch information
tymees authored Dec 7, 2023
2 parents 3b19d5d + f013dda commit 8831dea
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
14 changes: 14 additions & 0 deletions dev/main/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ class FormStylesForm(forms.Form):
widget=forms.RadioSelect,
)

searchable_select = forms.ChoiceField(
choices=[
(1, "Train"),
(2, "Bus"),
(3, "Aeroplane"),
(4, "Bike"),
(5, "Feet"),
(6, "Magical Unicorn"),
(6, "Broom"),
(6, "Thestrals"),
],
widget=core_fields.SearchableSelectWidget,
)

integer = forms.IntegerField()

float = forms.FloatField(help_text="Floating away")
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Hum IT Portal Development & ILS Labs",
"license": "Apache-2.0",
"dependencies": {
"uu-bootstrap": "git+ssh://git@github.com/DH-IT-Portal-Development/bootstrap-theme.git#1.5.0-alpha.0"
"uu-bootstrap": "git+ssh://git@github.com/DH-IT-Portal-Development/bootstrap-theme.git#1.5.0-alpha.1"
},
"scripts": {
"build-css": "yarn _build-css src/cdh/core/static/cdh.core/css/bootstrap.css --style=compressed",
Expand Down
18 changes: 18 additions & 0 deletions src/cdh/core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ def get_context(self, name, value, attrs):
return super().get_context(name, value, attrs)


class SearchableSelectWidget(BootstrapSelect):
"""A JS-baced widget for a searchable select. Currently using Select2 as
the backend."""

class Media:
js = [
'cdh.core/js/widget/searchable-select.js',
]

def get_context(self, name, value, attrs):
if "class" not in attrs:
attrs["class"] = ""

attrs["class"] += " dsc-select2"

return super().get_context(name, value, attrs)


class BootstrapCheckboxInput(CheckboxInput):
"""Override of Django's version to use the right Bootstrap classes"""

Expand Down
3 changes: 3 additions & 0 deletions src/cdh/core/static/cdh.core/js/widget/searchable-select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$(() => {
$('.dsc-select2').select2();
})
2 changes: 1 addition & 1 deletion src/cdh/federated_auth/static/cdh.federated_auth/base.css

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ to-regex-range@^5.0.1:
dependencies:
is-number "^7.0.0"

"uu-bootstrap@git+ssh://git@github.com/DH-IT-Portal-Development/bootstrap-theme.git#1.5.0-alpha.0":
version "1.5.0-alpha.0"
resolved "git+ssh://git@github.com/DH-IT-Portal-Development/bootstrap-theme.git#0bd740cae32d73770ed4ca7f4818612c8b4bff91"
"uu-bootstrap@git+ssh://git@github.com/DH-IT-Portal-Development/bootstrap-theme.git#1.5.0-alpha.1":
version "1.5.0-alpha.1"
resolved "git+ssh://git@github.com/DH-IT-Portal-Development/bootstrap-theme.git#0d3d52fc6abdfbefa802368b728f556916be53fb"
dependencies:
bootstrap "5.3.1"

0 comments on commit 8831dea

Please sign in to comment.