From 5052bd8ddcffd132de1bcadea716f71bfe584973 Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Sat, 27 Aug 2016 11:02:32 +0200 Subject: [PATCH] Fix BootsrapForm: placeholder on Input and Textarea only. --- CHANGELOG.rst | 5 +++++ cas_server/forms.py | 11 ++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 047a318..d7135d2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,11 @@ Added ----- * Add Django 1.10 support +Fixed +----- +* Fix BootsrapForm: placeholder on Input and Textarea only, use class form-control on + Input, Select and Textarea. + v0.7.1 - 2016-08-24 =================== diff --git a/cas_server/forms.py b/cas_server/forms.py index 54afb7f..cc6b2b0 100644 --- a/cas_server/forms.py +++ b/cas_server/forms.py @@ -12,6 +12,7 @@ from .default_settings import settings from django import forms +from django.forms import widgets from django.utils.translation import ugettext_lazy as _ import cas_server.utils as utils @@ -27,13 +28,13 @@ class BootsrapForm(forms.Form): def __init__(self, *args, **kwargs): super(BootsrapForm, self).__init__(*args, **kwargs) for field in self.fields.values(): - # Only tweak the fiel if it will be displayed - if not isinstance(field.widget, forms.HiddenInput): + # Only tweak the field if it will be displayed + if not isinstance(field.widget, widgets.HiddenInput): attrs = {} - if not isinstance(field.widget, forms.CheckboxInput): + if isinstance(field.widget, (widgets.Input, widgets.Select, widgets.Textarea)): attrs['class'] = "form-control" - if field.label: # pragma: no branch (currently all field are hidden or labeled) - attrs["placeholder"] = field.label + if isinstance(field.widget, (widgets.Input, widgets.Textarea)) and field.label: + attrs["placeholder"] = field.label if field.required: attrs["required"] = "required" field.widget.attrs.update(attrs)