Mercurial > p > roundup > code
comparison doc/upgrading.txt @ 8300:b99e76e76496
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').
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Wed, 19 Feb 2025 12:38:06 +0100 |
| parents | 6445e63bb423 |
| children | 3f43db05aa11 |
comparison
equal
deleted
inserted
replaced
| 8299:43899d99fc4d | 8300:b99e76e76496 |
|---|---|
| 225 .. _defusedxml: https://pypi.org/project/defusedxml/ | 225 .. _defusedxml: https://pypi.org/project/defusedxml/ |
| 226 | 226 |
| 227 Enable use of native date inputs (optional) | 227 Enable use of native date inputs (optional) |
| 228 ------------------------------------------- | 228 ------------------------------------------- |
| 229 | 229 |
| 230 Roundup now uses native date or datetime-local inputs for Date() | 230 Roundup now can use native ``date`` or ``datetime-local`` inputs for |
| 231 properties. These inputs take the place of the text input and | 231 ``Date()`` properties. These inputs take the place of the text input and |
| 232 calendar popup from earlier Roundup versions. Modern browsers | 232 calendar popup from earlier Roundup versions. Modern browsers come with |
| 233 come with a built-in calendar for date selection, so the | 233 a built-in calendar for date selection, so the ``(cal)`` calendar link |
| 234 ``(cal)`` calendar link is no longer needed. These native inputs | 234 is no longer needed. These native inputs show the date based on the |
| 235 show the date based on the browser's locale and translate terms | 235 browser's locale and translate terms into the local language. |
| 236 into the local language. | 236 |
| 237 | 237 Note that the date format is tied to the language setting in most |
| 238 If you do nothing, simple uses of the field() method will | 238 browsers, with some browsers you need special configurations to make the |
| 239 generate date inputs to allow selection of a date. Input fields | 239 browser use the operating system date format. |
| 240 for Date() properties will not have the ``(cal)`` link | 240 |
| 241 anymore. Complex uses will not be upgraded and will operate like | 241 By default the old input mechanism (using type=text inputs) is used. |
| 242 earlier Roundup versions. | 242 To enable native date input you need to set the config variable :: |
| 243 | 243 |
| 244 To upgrade all date properties, there are four changes to make: | 244 use_browser_date_input = yes |
| 245 | 245 |
| 246 1. Replace ``field`` calls with ``field_time`` where needed. | 246 in section ``[web]`` in the ``config.ini`` file. |
| 247 | 247 |
| 248 2. Remove the format argument from field() calls on Date() | 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() | |
| 249 properties. | 272 properties. |
| 250 | 273 |
| 251 3. Remove popcal() calls. | 274 4. Remove popcal() calls. |
| 252 | 275 |
| 253 4. Include datecopy.js in page.html. | 276 5. Include datecopy.js in page.html. |
| 254 | 277 |
| 255 Use field_time() where needed | 278 The ``display_time`` option |
| 256 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 279 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 257 | 280 |
| 258 The format used by ``field`` does not include hours, minutes or | 281 Both the ``Date()`` constructor and the ``field`` call take a |
| 259 seconds. If your users need to enter times, you should change | 282 ``display_time`` option which by default is ``yes`` in the ``Date()`` |
| 260 these calls to use ``field_time``. The arguments are the same as | 283 constructor and ``True`` in ``field``. The ``display_time`` setting of |
| 261 for field. | 284 ``Date()`` is inherited by the html property, so it doesn't need to be |
| 285 specified in each ``field()`` call for this property. | |
| 286 | |
| 287 When ``display_time`` is off, the date field does not include hours, | |
| 288 minutes or seconds. | |
| 262 | 289 |
| 263 Remove format argument | 290 Remove format argument |
| 264 ~~~~~~~~~~~~~~~~~~~~~~ | 291 ~~~~~~~~~~~~~~~~~~~~~~ |
| 265 | 292 |
| 266 Speaking of arguments, avoid setting the date format if you want | 293 Speaking of arguments, avoid setting the date ``format`` if you want to |
| 267 to use native date inputs. The date value needs a specific format | 294 use native date inputs. If you include the `format` argument in the |
| 268 for date or datetime-local inputs. If you include the `format` | 295 `field` method, it should be removed. |
| 269 argument in the `field` method, it should be removed. | 296 |
| 270 | 297 By default using a format argument will show the |
| 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 | |
| 286 | |
| 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 | |
| 295 popup calendar link. You can disable the link by setting | 298 popup calendar link. You can disable the link by setting |
| 296 ``popcal=False`` in the field() call. If you have:: | 299 ``popcal=False`` in the field() call. If you have:: |
| 297 | 300 |
| 298 tal:content="structure python:context.duedate.field( | 301 tal:content="structure python:context.duedate.field( |
| 299 placeholder='YYYY-MM, format='%Y-%m')" | 302 placeholder='YYYY-MM, format='%Y-%m')" |
| 300 | 303 |
| 301 changing it to:: | 304 changing it to:: |
| 302 | 305 |
| 303 tal:content="structure python:context.duedate.field( | 306 tal:content="structure python:context.duedate.field( |
| 304 type='text', | |
| 305 placeholder='YYYY-MM, format='%Y-%m', | 307 placeholder='YYYY-MM, format='%Y-%m', |
| 306 popcal=False)" | 308 popcal=False)" |
| 307 | 309 |
| 308 will generate the input as in Roundup 2.4 or earlier without a | 310 will generate the input as in Roundup 2.4 or earlier without a |
| 309 popcal link. | 311 popcal link. |
| 310 | 312 |
| 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 | |
| 324 Remove popcal | 313 Remove popcal |
| 325 ~~~~~~~~~~~~~ | 314 ~~~~~~~~~~~~~ |
| 326 | 315 |
| 327 If you use the ``popcal()`` method directly in your templates, you | 316 if you have enabled date input types in the configuration and you |
| 328 can remove them. The browser's native date selection calendar can | 317 use the ``popcal()`` method directly in your templates, you |
| 318 should remove them. The browser's native date selection calendar should | |
| 329 be used instead. | 319 be used instead. |
| 330 | 320 |
| 331 Add copy/paste/edit on double-click using datecopy.js | 321 Add copy/paste/edit on double-click using datecopy.js |
| 332 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 322 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 333 | 323 |
| 334 There is no way to copy/paste using a native datetime-local or | 324 When using date input types, |
| 335 date input. With the datecopy.js file installed, double-clicking | 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 | |
| 336 on the input turns it into a normal text input with the ability | 327 on the input turns it into a normal text input with the ability |
| 337 to copy, paste, or manually edit the date. | 328 to copy, paste, or manually edit the date. |
| 338 | 329 |
| 339 To set this up, take either ``datecopy.js`` or the smaller | 330 To set this up, take either ``datecopy.js`` or the smaller |
| 340 version, ``datecopy.min.js``, from the ``html`` folder of the | 331 version, ``datecopy.min.js``, from the ``html`` folder of the |
| 369 double-tap to activate text mode input. Firefox does not. | 360 double-tap to activate text mode input. Firefox does not. |
| 370 | 361 |
| 371 Revert native number inputs for Number() and Integer() (optional) | 362 Revert native number inputs for Number() and Integer() (optional) |
| 372 ----------------------------------------------------------------- | 363 ----------------------------------------------------------------- |
| 373 | 364 |
| 374 Roundup's field() method for properties of type Number() or | 365 Roundup's ``field()`` method for properties of type ``Number()`` or |
| 375 Integer() now use a native browser number input. | 366 ``Integer()`` now use a native browser number input by default. |
| 376 | 367 |
| 377 You can use the old style text inputs by calling the field | 368 This is configurable for *all* ``Number()`` and ``Integer()`` properties |
| 378 method with ``type="text"``. You can :ref:`follow the example | 369 with the config option ``use_browser_number_input`` in section ``[web]``. |
| 379 for setting the text argument on a Date() | 370 |
| 380 property. <revert_input_to_text>` for details. | 371 You can use the old style text inputs for individual fields |
| 381 | 372 by calling the field method with ``type="text"``. |
| 382 Note that the Integer() type also uses ``step="1"`` by default to | 373 |
| 374 Note that the ``Integer()`` type also uses ``step="1"`` by default to | |
| 383 add a stepper control and try to constrain the input to | 375 add a stepper control and try to constrain the input to |
| 384 integers. This can be overridden by passing a new step | 376 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. |
| 386 | 378 |
| 387 Change in REST response for invalid CORS requests (info) | 379 Change in REST response for invalid CORS requests (info) |
| 388 -------------------------------------------------------- | 380 -------------------------------------------------------- |
| 389 | 381 |
| 390 CORS_ preflight requests that are missing required headers can | 382 CORS_ preflight requests that are missing required headers can |
