From 47c0a197c8392bb216ff4e30bb6ea648e423ab96 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Fri, 6 Jun 2014 16:53:25 +0100 Subject: [PATCH] make password a required field when restriction_type = password --- wagtail/wagtailadmin/forms.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/wagtail/wagtailadmin/forms.py b/wagtail/wagtailadmin/forms.py index 3878eb473c..f3634faf08 100644 --- a/wagtail/wagtailadmin/forms.py +++ b/wagtail/wagtailadmin/forms.py @@ -83,3 +83,12 @@ class PageViewRestrictionForm(forms.Form): ('password', ugettext_lazy("This page is only viewable to users who enter this password:")), ], widget=forms.RadioSelect) password = forms.CharField(required=False) + + def clean(self): + cleaned_data = super(PageViewRestrictionForm, self).clean() + + if cleaned_data.get('restriction_type') == 'password' and not cleaned_data.get('password'): + self._errors["password"] = self.error_class([_('This field is required.')]) + del cleaned_data['password'] + + return cleaned_data