--- a/src/pyams_form/widget/__init__.py Tue Oct 09 16:18:11 2018 +0200
+++ b/src/pyams_form/widget/__init__.py Fri Oct 12 15:04:40 2018 +0200
@@ -12,8 +12,6 @@
__docformat__ = 'restructuredtext'
-
-# import standard library
import inspect
import json
import os
@@ -29,26 +27,25 @@
from z3c.form.browser.textarea import TextAreaWidget
from z3c.form.button import ButtonAction
from z3c.form.converter import BaseDataConverter, DatetimeDataConverter as BaseDatetimeDataConverter
-from z3c.form.interfaces import DISPLAY_MODE, IButtonAction, IDataConverter, IFieldWidget, INPUT_MODE, \
+from z3c.form.interfaces import DISPLAY_MODE, IButtonAction, IDataConverter, IFieldWidget, INPUT_MODE, ITextWidget, \
IWidgetLayoutTemplate, NO_VALUE
from z3c.form.widget import FieldWidget, WidgetLayoutFactory, WidgetTemplateFactory
from zope.interface import Interface, directlyProvides, implementer, implementer_only
from zope.pagetemplate.interfaces import IPageTemplate
from zope.schema.fieldproperty import FieldProperty
-from zope.schema.interfaces import IChoice, IDate, IDatetime, IList, ISet, ITime, ITuple
+from zope.schema.interfaces import IChoice, IDate, IDatetime, IFloat, IInt, IList, ISet, ITime, ITuple
-from pyams_form import _
-# import interfaces
from pyams_form.interfaces.form import IActionWidget, ICloseWidget, IColorWidget, IDateWidget, IDatetimeWidget, \
IFormLayer, IHTMLWidget, IResetWidget, ISEOTextLineWidget, ISelect2Widget, ITextLineListWidget, ITimeWidget
from pyams_form.schema import IActionButton, ICloseButton, IResetButton
from pyams_skin.interfaces.tinymce import ITinyMCEConfiguration
-# import packages
from pyams_utils.adapter import adapter_config
from pyams_utils.interfaces.data import IObjectData
from pyams_utils.schema import IColorField, IHTMLField, ITextLineListField
from pyams_utils.timezone import localgmtime, tztime
+from pyams_form import _
+
#
# Widget template configuration
@@ -250,6 +247,54 @@
#
+# Integer field widget
+#
+
+@widgettemplate_config(mode=INPUT_MODE, template='templates/integer-input.pt', layer=IFormLayer)
+@implementer_only(ITextWidget)
+class IntegerWidget(TextWidget):
+ """Integer widget"""
+
+ @property
+ def validate_rules(self):
+ rules = {'pattern': '\-?\d+'}
+ if self.field.min is not None:
+ rules['min'] = self.field.min
+ if self.field.max is not None:
+ rules['max'] = self.field.max
+ return json.dumps(rules)
+
+
+@adapter_config(context=(IInt, IFormLayer), provides=IFieldWidget)
+def IntegerFieldWidget(field, request):
+ return FieldWidget(field, IntegerWidget(request))
+
+
+#
+# Float field widget
+#
+
+@widgettemplate_config(mode=INPUT_MODE, template='templates/float-input.pt', layer=IFormLayer)
+@implementer_only(ITextWidget)
+class FloatWidget(TextWidget):
+ """Float widget"""
+
+ @property
+ def validate_rules(self):
+ rules = {'number': True}
+ if self.field.min is not None:
+ rules['min'] = self.field.min
+ if self.field.max is not None:
+ rules['max'] = self.field.max
+ return json.dumps(rules)
+
+
+@adapter_config(context=(IFloat, IFormLayer), provides=IFieldWidget)
+def FloatFieldWidget(field, request):
+ return FieldWidget(field, FloatWidget(request))
+
+
+#
# Date widget
#