Skip to content

Commit

Permalink
Do not show the Clear button for required Date or DateTime fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
thet committed Feb 10, 2017
1 parent f2f829c commit a807cf4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
17 changes: 17 additions & 0 deletions plone/app/z3cform/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions plone/app/z3cform/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down

1 comment on commit a807cf4

@jenkins-plone-org
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thet Jenkins CI reporting about code analysis
See the full report here: http://jenkins.plone.org/job/package-plone.app.z3cform/33/violations

plone/app/z3cform/inline_validation.py:15:1: C901 'InlineValidationView.__call__' is too complex (15)
plone/app/z3cform/templates.py:24:1: E305 expected 2 blank lines after class or function definition, found 1
plone/app/z3cform/tests/example.py:26:5: D001 found implements( replace it with zope.interface.implementer
plone/app/z3cform/tests/example.py:31:13: Q000 Remove bad quotes.
plone/app/z3cform/tests/example.py:44:34: Q000 Remove bad quotes.
plone/app/z3cform/tests/example.py:55:13: Q000 Remove bad quotes.
plone/app/z3cform/tests/example.py:70:30: Q000 Remove bad quotes.
plone/app/z3cform/tests/example.py:71:55: Q000 Remove bad quotes.
plone/app/z3cform/tests/example.py:72:52: Q000 Remove bad quotes.
plone/app/z3cform/tests/example.py:77:13: Q000 Remove bad quotes.
plone/app/z3cform/tests/test_objectsubform.py:21:15: Q000 Remove bad quotes.
plone/app/z3cform/tests/test_objectsubform.py:26:15: D001 found implements( replace it with zope.interface.implementer
plone/app/z3cform/tests/test_objectsubform.py:46:15: Q000 Remove bad quotes.
plone/app/z3cform/tests/test_objectsubform.py:49:19: Q000 Remove bad quotes.
plone/app/z3cform/tests/test_objectsubform.py:57:13: Q000 Remove bad quotes.
plone/app/z3cform/tests/test_objectsubform.py:62:15: D001 found implements( replace it with zope.interface.implementer
plone/app/z3cform/tests/test_widgets.py:41:5: D001 found implements( replace it with zope.interface.implementer
plone/app/z3cform/tests/test_widgets.py:1273:40: Q000 Remove bad quotes.
plone/app/z3cform/tests/test_utils.py:21:9: E731 do not assign a lambda expression, use a def
plone/app/z3cform/tests/test_widget.py:12:15: D001 found implements( replace it with zope.interface.implementer

Follow these instructions to reproduce it locally.

Please sign in to comment.