From f2f829cede913647b955eb0dcc2619e6eeb54f9d Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Fri, 10 Feb 2017 00:48:51 +0100 Subject: [PATCH 1/2] Test fixes for plone.app.widgets 2.1. --- CHANGES.rst | 3 +++ plone/app/z3cform/tests/test_widgets.py | 13 ++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 3a8ab1fb..bcb29c7d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,6 +14,9 @@ New features: Bug fixes: +- Test fixes for plone.app.widgets 2.1. + [thet] + - remove deprecated __of__ for browserviews [pbauer] diff --git a/plone/app/z3cform/tests/test_widgets.py b/plone/app/z3cform/tests/test_widgets.py index d6c94c1d..9cbd0954 100644 --- a/plone/app/z3cform/tests/test_widgets.py +++ b/plone/app/z3cform/tests/test_widgets.py @@ -164,7 +164,6 @@ def test_widget(self): 'firstDay': 0, 'min': [current_year - 100, 1, 1], 'max': [current_year + 20, 1, 1], - 'clear': u'Clear', 'format': 'mmmm d, yyyy', 'monthsFull': [u'January', u'February', u'March', u'April', u'May', u'June', u'July', @@ -175,14 +174,15 @@ def test_widget(self): 'weekdaysFull': [u'Sunday', u'Monday', u'Tuesday', u'Wednesday', u'Thursday', u'Friday', u'Saturday'], - 'today': u'Today', 'selectYears': 200, 'placeholder': u'Enter date...', 'monthsShort': [u'Jan', u'Feb', u'Mar', u'Apr', u'May', u'Jun', u'Jul', u'Aug', u'Sep', u'Oct', u'Nov', u'Dec'] }, - 'time': False + 'time': False, + 'today': u'Today', + 'clear': u'Clear', } }, self.widget._base_args(), @@ -258,7 +258,6 @@ def test_widget(self): 'firstDay': 0, 'min': [current_year - 100, 1, 1], 'max': [current_year + 20, 1, 1], - 'clear': u'Clear', 'format': 'mmmm d, yyyy', 'monthsFull': [u'January', u'February', u'March', u'April', u'May', u'June', u'July', @@ -269,7 +268,6 @@ def test_widget(self): 'weekdaysFull': [u'Sunday', u'Monday', u'Tuesday', u'Wednesday', u'Thursday', u'Friday', u'Saturday'], - 'today': u'Today', 'selectYears': 200, 'placeholder': u'Enter date...', 'monthsShort': [u'Jan', u'Feb', u'Mar', u'Apr', u'May', @@ -278,10 +276,11 @@ def test_widget(self): }, 'time': { 'placeholder': u'Enter time...', - 'today': u'Today', 'format': 'h:i a', 'interval': 15 - } + }, + 'today': u'Today', + 'clear': u'Clear', } }, self.widget._base_args(), From a807cf4f57bd0bd68899ced2f606d383cde10f8e Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Fri, 10 Feb 2017 01:04:46 +0100 Subject: [PATCH 2/2] Do not show the Clear button for required Date or DateTime fields. --- CHANGES.rst | 3 ++- plone/app/z3cform/tests/test_widgets.py | 17 +++++++++++++++++ plone/app/z3cform/widget.py | 3 +++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index bcb29c7d..73794301 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,7 +10,8 @@ Breaking changes: New features: -- *add item here* +- Do not show the "Clear" button for required Date or DateTime fields. + [thet] Bug fixes: diff --git a/plone/app/z3cform/tests/test_widgets.py b/plone/app/z3cform/tests/test_widgets.py index 9cbd0954..61a3e018 100644 --- a/plone/app/z3cform/tests/test_widgets.py +++ b/plone/app/z3cform/tests/test_widgets.py @@ -148,6 +148,7 @@ def setUp(self): self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'}) self.field = Date(__name__='datefield') + self.field.required = False self.widget = DateWidget(self.request) self.widget.field = self.field self.widget.pattern_options = {'date': {'firstDay': 0}} @@ -188,6 +189,13 @@ def test_widget(self): self.widget._base_args(), ) + def test_widget_required(self): + """Required fields should not have a "Clear" button. + """ + self.field.required = True + base_args = self.widget._base_args() + self.assertEqual(base_args['pattern_options']['clear'], False) + def test_data_converter(self): from plone.app.z3cform.widget import DateWidgetConverter converter = DateWidgetConverter(self.field, self.widget) @@ -240,7 +248,9 @@ def setUp(self): self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'}) self.field = Datetime(__name__='datetimefield') + self.field.required = False self.widget = DatetimeWidget(self.request) + self.widget.field = self.field self.widget.pattern_options = { 'date': {'firstDay': 0}, 'time': {'interval': 15} @@ -286,6 +296,13 @@ def test_widget(self): self.widget._base_args(), ) + def test_widget_required(self): + """Required fields should not have a "Clear" button. + """ + self.field.required = True + base_args = self.widget._base_args() + self.assertEqual(base_args['pattern_options']['clear'], False) + def test_data_converter(self): from plone.app.z3cform.widget import DatetimeWidgetConverter converter = DatetimeWidgetConverter(self.field, self.widget) diff --git a/plone/app/z3cform/widget.py b/plone/app/z3cform/widget.py index 56cec146..9d8406ee 100644 --- a/plone/app/z3cform/widget.py +++ b/plone/app/z3cform/widget.py @@ -135,6 +135,9 @@ def _base_args(self): self.value) or u'').strip() args.setdefault('pattern_options', {}) + if self.field.required: + # Required fields should not have a "Clear" button + args['pattern_options']['clear'] = False args['pattern_options'] = dict_merge( get_date_options(self.request), args['pattern_options'])