Commit 57ace587 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

Formulator: add a new input style "number" in DateTimeField.

parent f32420d9
...@@ -136,6 +136,8 @@ class DateTimeField(ZMIField): ...@@ -136,6 +136,8 @@ class DateTimeField(ZMIField):
self.sub_form = create_datetime_text_sub_form() self.sub_form = create_datetime_text_sub_form()
elif input_style == 'list': elif input_style == 'list':
self.sub_form = create_datetime_list_sub_form() self.sub_form = create_datetime_list_sub_form()
elif input_style == 'number':
self.sub_form = create_datetime_number_sub_form()
else: else:
assert 0, "Unknown input_style '%s'" % input_style assert 0, "Unknown input_style '%s'" % input_style
...@@ -147,6 +149,8 @@ class DateTimeField(ZMIField): ...@@ -147,6 +149,8 @@ class DateTimeField(ZMIField):
year_field = self.sub_form.get_field('year', include_disabled=1) year_field = self.sub_form.get_field('year', include_disabled=1)
year_field.overrides['items'] = BoundMethod(self, year_field.overrides['items'] = BoundMethod(self,
'_override_year_items') '_override_year_items')
elif value == 'number':
self.sub_form = create_datetime_number_sub_form()
else: else:
assert 0, "Unknown input_style." assert 0, "Unknown input_style."
self.on_value_css_class_changed(self.values['css_class']) self.on_value_css_class_changed(self.values['css_class'])
...@@ -299,6 +303,71 @@ def create_datetime_list_sub_form(): ...@@ -299,6 +303,71 @@ def create_datetime_list_sub_form():
sub_form.add_fields([hour, minute, ampm, timezone], "time") sub_form.add_fields([hour, minute, ampm, timezone], "time")
return sub_form return sub_form
def create_datetime_number_sub_form():
sub_form = BasicForm()
year = IntegerField('year',
title="Year",
required=0,
input_type='number',
extra='min="0" max="9999"',
display_width=4,
display_maxwidth=4,
max_length=4)
month = IntegerField('month',
title="Month",
required=0,
input_type='number',
extra='min="1" max="12"',
display_width=2,
display_maxwidth=2,
max_length=2)
day = IntegerField('day',
title="Day",
required=0,
input_type='number',
extra='min="1" max="31"',
display_width=2,
display_maxwidth=2,
max_length=2)
sub_form.add_group("date")
sub_form.add_fields([year, month, day], "date")
hour = IntegerField('hour',
title="Hour",
required=0,
input_type='number',
extra='min="0" max="23"',
display_width=2,
display_maxwidth=2,
max_length=2)
minute = IntegerField('minute',
title="Minute",
required=0,
input_type='number',
extra='min="0" max="59"',
display_width=2,
display_maxwidth=2,
max_length=2)
ampm = StringField('ampm',
title="am/pm",
required=0,
display_width=2,
display_maxwidth=2,
max_length=2)
timezone = ListField('timezone',
title = "Timezone",
required = 0,
default = 'GMT',
items = Widget.gmt_timezones,
size = 1)
sub_form.add_fields([hour, minute, ampm, timezone], "time")
return sub_form
def create_items(start, end, digits=0): def create_items(start, end, digits=0):
result = [("-", "")] result = [("-", "")]
if digits: if digits:
......
...@@ -1376,7 +1376,8 @@ class DateTimeWidget(Widget): ...@@ -1376,7 +1376,8 @@ class DateTimeWidget(Widget):
"as text, while 'list' will use dropdown lists instead."), "as text, while 'list' will use dropdown lists instead."),
default="text", default="text",
items=[("text", "text"), items=[("text", "text"),
("list", "list")], ("list", "list"),
("number", "number")],
size=1) size=1)
default_timezone = fields.ListField('default_timezone', default_timezone = fields.ListField('default_timezone',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment