diff --git a/tw2/forms/calendars.py b/tw2/forms/calendars.py index 5904c40..9528848 100644 --- a/tw2/forms/calendars.py +++ b/tw2/forms/calendars.py @@ -24,6 +24,8 @@ Portions of this document have been taken in part and modified from the original tw.forms codebase written primarily by Alberto Valaverde + +TODO: HTML5 type attribute support with native support detection and fallback """ import re from datetime import datetime, date diff --git a/tw2/forms/widgets.py b/tw2/forms/widgets.py index c2b7e5b..628b804 100755 --- a/tw2/forms/widgets.py +++ b/tw2/forms/widgets.py @@ -61,8 +61,15 @@ class HTML5MinMaxMixin(twc.Widget): attribute=True, default=None) +class HTML5StepMixin(twc.Widget): + '''HTML5 mixin for input field step size''' + step = twc.Param('The step size between numbers', + attribute=True, default=None) + + class HTML5KitchenSinkMixin(HTML5PatternMixin, - HTML5PlaceholderMixin, HTML5LengthMixin, HTML5MinMaxMixin): + HTML5PlaceholderMixin, HTML5LengthMixin, HTML5MinMaxMixin, + HTML5StepMixin): '''HTML5 mixin which aggregates all HTML5 mixins''' pass @@ -77,12 +84,15 @@ class InputField(FormField): required = twc.Param('Input field is required', attribute=True, default=None) + autofocus = twc.Param('Autofocus form field (HTML5 only)', + attribute=True, default=False) + template = "tw2.forms.templates.input_field" def prepare(self): super(InputField, self).prepare() self.safe_modify('attrs') - self.attrs['required'] = 'required' if self.required in [True, 'required'] else None + self.attrs['required'] = 'required' if self.required in [True, 'required'] else None # Why not 'required' if self.required in [True, 'required'] else None ? self.required = None # Why? @@ -296,6 +306,61 @@ def prepare(self): self.attrs['src'] = self.src # TBD: hack! +#-- +# HTML5 Fields +#-- + + +class EmailField(TextField): + '''An email input field (HTML5 only). + + Will fallback to a normal text input field on browser not supporting HTML5. + ''' + type = 'email' + validator = twc.EmailValidator + + +class URLField(TextField): + '''An url input field (HTML5 only). + + Will fallback to a normal text input field on browser not supporting HTML5. + ''' + type = 'url' + validator = twc.URLValidator + + +class NumberField(TextField): + '''A number spinbox (HTML5 only). + + Will fallback to a normal text input field on browser not supporting HTML5. + ''' + type = 'number' + + +class RangeField(TextField): + '''A number slider (HTML5 only). + + Will fallback to a normal text input field on browser not supporting HTML5. + ''' + type = 'range' + + +class SearchField(TextField): + '''A search box (HTML5 only). + + Will fallback to a normal text input field on browser not supporting HTML5. + ''' + type = 'search' + + +class ColorField(TextField): + '''A color picker field (HTML5 only). + + Will fallback to a normal text input field on browser not supporting HTML5. + ''' + type = 'color' + + #-- # Selection fields #-- @@ -732,6 +797,8 @@ class Form(twc.DisplayOnlyWidget): buttons = twc.Param('List of additional buttons to be placed at the ' + 'bottom of the form', default=[]) + novalidate = twc.Param('Turn off HTML5 form validation', + attribute=True, default=None) attrs = {'enctype': 'multipart/form-data'} id_suffix = 'form'