Skip to content

Commit 926b5db

Browse files
committed
Make native date and number elements configurable
Now for Number() and Integer() properties the browser-native number format can be configured with the use_browser_number_input config item in seciont [web]. The default is 'yes'. For Date() properties the config item is use_browser_date_input (also in section [web]) but the default is 'no'. In addition when defining Date() properties, these now have a parameter 'display_time' which defaults to 'yes' and a 'format' parameter which defaults to None. These set defaults for the field() method of the DateHTMLProperty which have the same parameters (but the display_time parameter of field() takes a boolean, not 'yes'/'no').
1 parent 56ba6f8 commit 926b5db

File tree

11 files changed

+284
-271
lines changed

11 files changed

+284
-271
lines changed

.hgignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ website/www/COPYING.txt
4747
website/www/docs
4848
website/www/html/
4949
.pytest_cache
50+
.hypothesis

CHANGES.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ Fixed:
7979
input fields. Thinko in the code. (John Rouillard)
8080
- issue2551390 - Replace text input/calendar popup with native
8181
date input. Also add double-click and exit keyboard handlers to
82-
allow copy/paste/editing the text version of the date. (John
83-
Rouillard)
82+
allow copy/paste/editing the text version of the date. Configurable
83+
via the use_browser_date_input setting in the [web] section of
84+
config.ini. By default browser native dates are turned off.
85+
(John Rouillard, Ralf Schlatterbeck)
8486
- issue1895197 - translated help texts in admin.py not displayed
8587
correctly. (Initial patch tobias-herp, John Rouillard)
8688
- issue2551238 - roundup-server should exit with error if -d
@@ -129,7 +131,9 @@ Features:
129131
allow reporting an error to the user from a template. (John
130132
Rouillard)
131133
- Use native number type input for Number() and Integer()
132-
properties. Integer() uses step=1 as well. (John Rouillard)
134+
properties. Integer() uses step=1 as well. Configurable via the
135+
use_browser_number_input setting in the [web] section of config.ini
136+
(John Rouillard, Ralf Schlatterbeck)
133137
- issue2551231 - template.py-HTMLClass::classhelp doesn't merge
134138
user defined classes. It now merges them in. (John Rouillard)
135139

doc/customizing.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ caches the schema).
9090
<td tal:content="structure context/due_date/field" />
9191
</tr>
9292

93-
If you want to show the date and time for due_date then do this instead::
93+
If you want to show only the date part of due_date then do this instead:
9494

9595
<tr>
9696
<th>Due Date</th>
97-
<td tal:content="structure context/due_date/field_time" />
97+
<td tal:content="structure python:context.due_date.field(display_time=False)" />
9898
</tr>
9999

100100
3. Add the property to the ``issue.index.html`` page::

doc/reference.txt

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3070,8 +3070,11 @@ There are several methods available on these wrapper objects:
30703070
tri-state yes/no/neither selection. This method may take some
30713071
arguments:
30723072

3073-
size (default 30)
3074-
Sets the width in characters of the edit field
3073+
display_time (Date properties only)
3074+
By default this uses the display_time paramter of the
3075+
Date property (which by default is True) and displays
3076+
date and time for Date properties. You can set this to
3077+
False for displaying only the date.
30753078

30763079
format (Date properties only)
30773080
Sets the format of the date in the field - uses the
@@ -3083,25 +3086,33 @@ There are several methods available on these wrapper objects:
30833086
text edit box with the year and month part of your
30843087
date.
30853088

3086-
type (depends on property type)
3087-
Sets the type property of the input. To change a date
3088-
property field from a native date input to a text
3089-
input you would use ``type="text"``.
3089+
labelfirst (Boolean properties only)
3090+
place the labels before the radio buttons
30903091

30913092
popcal (Date properties only)
30923093
Include a link to the JavaScript-based popup calendar
3093-
for date selection. Defaults to off/False since native
3094-
date inputs supply popup calendars.
3094+
for date selection. Defaults to off/False when browser
3095+
native dates are in use and on/True otherwise because
3096+
browser native dates support a date popup on most
3097+
browsers.
3098+
3099+
size (default 30)
3100+
Sets the width in characters of the edit field
3101+
3102+
type (depends on property type)
3103+
Sets the type property of the input. To change a date
3104+
property field from a native date input to a text
3105+
input you would use ``type="text"``. For Date properties
3106+
the type cannot be set by the user and is enforced via
3107+
the configuration (if browser native date input should
3108+
be used).
30953109

30963110
y_label, n_label, u_label (Boolean properties only)
30973111
Set the labels for the true/false/undefined
30983112
states. If u_label is defined, it produces a
30993113
tri-state radio button selector. Otherwise, it
31003114
allows selection of true/yes or false/no only.
31013115

3102-
labelfirst (Boolean properties only)
3103-
place the labels before the radio buttons
3104-
31053116
Other arguments are added as properties directly on the
31063117
input tag. For example::
31073118

@@ -3115,11 +3126,6 @@ There are several methods available on these wrapper objects:
31153126
attribute without a value. This is useful for boolean
31163127
properties like ``required``.
31173128

3118-
field_time (Date properties only)
3119-
Create a browser native input for editing date and time.
3120-
The field method creates an input for editing
3121-
month/day/year (without time).
3122-
31233129
rst only on String properties - render the value of the property
31243130
as ReStructuredText (requires the :ref:`Docutils
31253131
module to be installed separately<install/docutils>`).
@@ -3179,9 +3185,10 @@ There are several methods available on these wrapper objects:
31793185
is returned if the value is ``None`` otherwise it
31803186
is converted to a string.
31813187

3182-
popcal This is deprecated with Roundup 2.5 which uses the
3183-
native HTML5 date input. The native date input
3184-
includes a calendar popup on modern broswers.
3188+
popcal This is deprecated with Roundup 2.5 which either uses the
3189+
native HTML5 date input or can generate a date popup with
3190+
the popcal option of the ``field`` method. The native date
3191+
input includes a calendar popup on modern broswers.
31853192

31863193
Generate a link to a popup calendar which may be used to
31873194
edit the date field, for example::
@@ -3193,6 +3200,9 @@ There are several methods available on these wrapper objects:
31933200

31943201
<span tal:replace="structure context/due/field" />
31953202
<span tal:replace="structure context/due/popcal" />
3203+
3204+
Since the ``field`` by default already produces a popup
3205+
calendar this use is deprecated.
31963206

31973207
menu only on Link and Multilink properties - render a form select
31983208
list for this property. Takes a number of optional arguments

doc/tracker_config.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,26 @@
624624
# Default: disabled
625625
jwt_secret = disabled
626626

627+
# HTML input elements for Date properties: This determines
628+
# if we use the input type 'datetime-local' (or 'date') for
629+
# date input fields. If the option is turned off (the default),
630+
# the type is set to 'text'. Since the widgets generated by
631+
# browsers determine the date format from the language
632+
# setting (it is currently not possible to force the
633+
# international date format server-side) and some browsers
634+
# ignore the date format set by the operating system, the
635+
# default is 'no'.
636+
# Allowed values: yes, no
637+
# Default: no
638+
use_browser_date_input = no
639+
640+
# HTML input elements for Number properties: This determines
641+
# if we use the input type 'number' for Number (and Integer)
642+
# properties. If set to 'no' we use input type 'text'.
643+
# Allowed values: yes, no
644+
# Default: yes
645+
use_browser_number_input = no
646+
627647
.. index:: config.ini; sections rdbms
628648
.. _`config-ini-section-rdbms`:
629649
.. code:: ini

doc/upgrading.txt

Lines changed: 73 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -227,71 +227,74 @@ defusedxml.
227227
Enable use of native date inputs (optional)
228228
-------------------------------------------
229229

230-
Roundup now uses native date or datetime-local inputs for Date()
231-
properties. These inputs take the place of the text input and
232-
calendar popup from earlier Roundup versions. Modern browsers
233-
come with a built-in calendar for date selection, so the
234-
``(cal)`` calendar link is no longer needed. These native inputs
235-
show the date based on the browser's locale and translate terms
236-
into the local language.
237-
238-
If you do nothing, simple uses of the field() method will
239-
generate date inputs to allow selection of a date. Input fields
240-
for Date() properties will not have the ``(cal)`` link
241-
anymore. Complex uses will not be upgraded and will operate like
242-
earlier Roundup versions.
243-
244-
To upgrade all date properties, there are four changes to make:
245-
246-
1. Replace ``field`` calls with ``field_time`` where needed.
247-
248-
2. Remove the format argument from field() calls on Date()
230+
Roundup now can use native ``date`` or ``datetime-local`` inputs for
231+
``Date()`` properties. These inputs take the place of the text input and
232+
calendar popup from earlier Roundup versions. Modern browsers come with
233+
a built-in calendar for date selection, so the ``(cal)`` calendar link
234+
is no longer needed. These native inputs show the date based on the
235+
browser's locale and translate terms into the local language.
236+
237+
Note that the date format is tied to the language setting in most
238+
browsers, with some browsers you need special configurations to make the
239+
browser use the operating system date format.
240+
241+
By default the old input mechanism (using type=text inputs) is used.
242+
To enable native date input you need to set the config variable ::
243+
244+
use_browser_date_input = yes
245+
246+
in section ``[web]`` in the ``config.ini`` file.
247+
248+
If native date input is used, simple uses of the ``field()`` method will
249+
generate ``datetime-local`` inputs to allow selection of a date and time.
250+
Input fields for ``Date()`` properties will not have the ``(cal)`` link
251+
anymore. If fields should only use a date (without time) you can specify
252+
the parameter ``display_time=no`` in ``schema.py`` for a ``Date()``
253+
property (the default is ``yes``). This will use ``date`` inputs in the
254+
generated html to select a date only. If you need this only for a single
255+
date, the ``field()`` method now has a boolean parameter
256+
``display_time`` (which by default is set to the ``display_time``
257+
parameter of ``Date()``)
258+
259+
Complex uses using a ``format`` specification in ``field()`` will not be
260+
upgraded and will operate like earlier Roundup versions. In addition the
261+
``format`` can now also be specified in the ``Date()`` constructor.
262+
263+
To upgrade all date properties, there are five changes to make:
264+
265+
1. Configure ``use_browser_date_input = yes`` in section ``[web]`` in
266+
``config.ini``
267+
268+
2. Optionally add ``display_time = no`` in the schema for Date()
269+
properties that should have no time displayed
270+
271+
3. Remove the format argument from field() calls on Date()
249272
properties.
250273

251-
3. Remove popcal() calls.
274+
4. Remove popcal() calls.
275+
276+
5. Include datecopy.js in page.html.
252277

253-
4. Include datecopy.js in page.html.
278+
The ``display_time`` option
279+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
254280

255-
Use field_time() where needed
256-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
281+
Both the ``Date()`` constructor and the ``field`` call take a
282+
``display_time`` option which by default is ``yes`` in the ``Date()``
283+
constructor and ``True`` in ``field``. The ``display_time`` setting of
284+
``Date()`` is inherited by the html property, so it doesn't need to be
285+
specified in each ``field()`` call for this property.
257286

258-
The format used by ``field`` does not include hours, minutes or
259-
seconds. If your users need to enter times, you should change
260-
these calls to use ``field_time``. The arguments are the same as
261-
for field.
287+
When ``display_time`` is off, the date field does not include hours,
288+
minutes or seconds.
262289

263290
Remove format argument
264291
~~~~~~~~~~~~~~~~~~~~~~
265292

266-
Speaking of arguments, avoid setting the date format if you want
267-
to use native date inputs. The date value needs a specific format
268-
for date or datetime-local inputs. If you include the `format`
269-
argument in the `field` method, it should be removed.
270-
271-
The `field` method uses the format ``%Y-%m-%d``. The
272-
``field_time`` method uses the format ``%Y-%m-%dT%H:%M:%S``. If
273-
you use these exact formats, Roundup will accept them and use a
274-
native date input.
275-
276-
.. highlight:: text
277-
278-
If you use an format that doesn't match, you will see a text
279-
input and a logged warning message like::
280-
281-
Format '%Y-%m' prevents use of modern date input.
282-
Remove format from field() call in template test.item.
283-
Using text input.
284-
285-
.. highlight:: default
293+
Speaking of arguments, avoid setting the date ``format`` if you want to
294+
use native date inputs. If you include the `format` argument in the
295+
`field` method, it should be removed.
286296

287-
The log message will appear if your logging level is set to
288-
WARNING or lower. (Refer to your tracker's :ref:`config.ini
289-
logging section <config-ini-section-logging>` for details on
290-
logging levels.)
291-
292-
If you want to use a text input for a specific date format, you
293-
can add ``type="text"`` to the field() argument list to suppress
294-
the warning. By default using a format argument will show the
297+
By default using a format argument will show the
295298
popup calendar link. You can disable the link by setting
296299
``popcal=False`` in the field() call. If you have::
297300

@@ -301,38 +304,26 @@ popup calendar link. You can disable the link by setting
301304
changing it to::
302305

303306
tal:content="structure python:context.duedate.field(
304-
type='text',
305307
placeholder='YYYY-MM, format='%Y-%m',
306308
popcal=False)"
307309

308310
will generate the input as in Roundup 2.4 or earlier without a
309311
popcal link.
310312

311-
.. _revert_input_to_text:
312-
313-
If you are using a path expression like::
314-
315-
tal:content="context/duedate/field"
316-
317-
change it to::
318-
319-
tal:content="structure python:context.duedate.field(
320-
type='text')"
321-
322-
to get the input from before Roundup 2.5 with a popcal link.
323-
324313
Remove popcal
325314
~~~~~~~~~~~~~
326315

327-
If you use the ``popcal()`` method directly in your templates, you
328-
can remove them. The browser's native date selection calendar can
316+
if you have enabled date input types in the configuration and you
317+
use the ``popcal()`` method directly in your templates, you
318+
should remove them. The browser's native date selection calendar should
329319
be used instead.
330320

331321
Add copy/paste/edit on double-click using datecopy.js
332322
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
333323

334-
There is no way to copy/paste using a native datetime-local or
335-
date input. With the datecopy.js file installed, double-clicking
324+
When using date input types,
325+
there is no way to copy/paste using a native ``datetime-local`` or
326+
``date`` input. With the ``datecopy.js`` file installed, double-clicking
336327
on the input turns it into a normal text input with the ability
337328
to copy, paste, or manually edit the date.
338329

@@ -371,18 +362,19 @@ double-tap to activate text mode input. Firefox does not.
371362
Revert native number inputs for Number() and Integer() (optional)
372363
-----------------------------------------------------------------
373364

374-
Roundup's field() method for properties of type Number() or
375-
Integer() now use a native browser number input.
365+
Roundup's ``field()`` method for properties of type ``Number()`` or
366+
``Integer()`` now use a native browser number input by default.
367+
368+
This is configurable for *all* ``Number()`` and ``Integer()`` properties
369+
with the config option ``use_browser_number_input`` in section ``[web]``.
376370

377-
You can use the old style text inputs by calling the field
378-
method with ``type="text"``. You can :ref:`follow the example
379-
for setting the text argument on a Date()
380-
property. <revert_input_to_text>` for details.
371+
You can use the old style text inputs for individual fields
372+
by calling the field method with ``type="text"``.
381373

382-
Note that the Integer() type also uses ``step="1"`` by default to
374+
Note that the ``Integer()`` type also uses ``step="1"`` by default to
383375
add a stepper control and try to constrain the input to
384376
integers. This can be overridden by passing a new step
385-
(e.g. ``step="50"``) to the field() method.
377+
(e.g. ``step="50"``) to the ``field()`` method.
386378

387379
Change in REST response for invalid CORS requests (info)
388380
--------------------------------------------------------

doc/user_guide.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Integer Properties
132132

133133
These fields take a whole/integer number without decimal marker like
134134
``123``, ``+123``, ``-123``. Exponents are not supported. Your browser
135-
may show an up/down arrow spinner to change the value.
135+
may show an up/down arrow spinner to change the value.
136136

137137
Boolean properties
138138
~~~~~~~~~~~~~~~~~~
@@ -178,9 +178,11 @@ Classhelper`_ for details.
178178
Date properties
179179
~~~~~~~~~~~~~~~
180180

181-
Date properties are usually shown using a native HTML date
182-
element. This provides a calendar button for choosing the
183-
date. The date is shown in the normal format for your location.
181+
Date properties can be shown using a native HTML date (or
182+
datetime-local) element by setting ``use_browser_date_input=yes`` in
183+
section ``[web]`` in ``config.ini``. This provides a calendar button for
184+
choosing the date. The date is shown in the normal format for your
185+
location.
184186

185187
Native date inputs do not allow the use of partial forms as
186188
defined below. For this reason, you may edit a date/time

0 commit comments

Comments
 (0)