From d5ee13b0f01871ec93a37bf12242e88e4be26af9 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 16 Apr 2018 18:48:59 +0200 Subject: Widgets: add a switch --- ishtar_common/widgets.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'ishtar_common') diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index ec3f8b011..2df06cf21 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -260,6 +260,20 @@ class DeleteWidget(forms.CheckboxInput): return mark_safe(output) +class SwitchWidget(forms.CheckboxInput): + def render(self, name, value, attrs=None, renderer=None): + attrs = self.build_attrs( + attrs, {"name": name, "value": '0', + 'class': "switch", + 'type': 'checkbox'} + ) + final_attrs = flatatt(attrs) + output = u""" + +""".format(final_attrs, attrs['id']) + return mark_safe(output) + + class ImageFileInput(ClearableFileInput): template_name = 'widgets/image_input.html' NO_FORM_CONTROL = True -- cgit v1.2.3