Edgewall Software

Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#11413 closed defect (fixed)

Difficult to edit directly text field with date/time picker

Reported by: Jun Omae Owned by: Jun Omae
Priority: normal Milestone: 1.0.2
Component: general Version: 1.0.1
Severity: normal Keywords: datepicker, jqueryui
Cc: Branch:
Release Notes:

Prevent moving the cursor to end of field with datetime picker when editing hours part.

API Changes:
Internal Changes:


The date/time picker on Trac has some issues. It is difficult to edit directly caused by the following issue.

  1. Restore immediately the value after removing end of the text field with backspace key
  2. Move the cursor to end of the text field after removing hours part
  3. Fill the text field with today after focusing even if it's empty

See https://groups.google.com/d/msg/trac-users/1Xi8cz-m1KY/7E8ZgU6WjKgJ.

Attachments (0)

Change History (8)

comment:1 by Jun Omae, 9 years ago

I've tried the latest of jquery-ui-addons.js, v1.4.3. But it isn't fixed.

I investigated it and noticed that timezone list must have default timezone even if the timezone is not used. The default timezone is at tags/trac-1.0.1/trac/htdocs/js/jquery-ui-i18n.js@:42#L28.

  • trac/web/chrome.py

    diff --git a/trac/web/chrome.py b/trac/web/chrome.py
    index 6e82b5d..a47d24e 100644
    a b class Chrome(Component):  
    11411141            'first_week_day': get_first_week_day_jquery_ui(req),
    11421142            'timepicker_separator': 'T' if is_iso8601 else ' ',
    11431143            'show_timezone': is_iso8601,
     1144            # default timezone must be included
    11441145            'timezone_list': get_timezone_list_jquery_ui() \
    1145                              if is_iso8601 else [],
     1146                             if is_iso8601 else ['Z'],
    11461147            'timezone_iso8601': is_iso8601,
    11471148        })
    11481149        add_script(req, 'common/js/jquery-ui-i18n.js')

The patch would fix the issues. However, even with the patch, the cursor is moved to end when invalid hours is typed.

comment:2 by Jun Omae, 9 years ago

Milestone: next-stable-1.0.x1.0.2
Release Notes: modified (diff)
Resolution: fixed
Status: newclosed

Committed with tests in [12370] and merged in [12371].

comment:3 by Jun Omae, 9 years ago

Owner: set to Jun Omae
Release Notes: modified (diff)

comment:4 by Ryan J Ollos, 9 years ago

Keywords: jqueryui added

in reply to:  1 comment:5 by Ryan J Ollos, 7 years ago

Replying to Jun Omae:

I've tried the latest of jquery-ui-addons.js, v1.4.3. But it isn't fixed.

It wasn't clear to me if the fix committed is a workaround that may someday not be needed. Anyway, confirmed the fix is still needed with v1.5.5 of the jQuery UI Timepicker (upgraded in #11019).

comment:6 by Jun Omae, 7 years ago

Hmmm. It seems the spec of timezoneList option has been changed and Z in format has been added. However, this patch still doesn't fix the difficulty of direct editing when selected format is iso8601.

  • trac/util/datefmt.py

    diff --git a/trac/util/datefmt.py b/trac/util/datefmt.py
    index ef771174f..1b16439f5 100644
    a b def get_date_format_jquery_ui(locale):  
    353353def get_time_format_jquery_ui(locale):
    354354    """Get the time format for the jQuery UI timepicker addon."""
    355355    if locale == 'iso8601':
    356         return 'HH:mm:ssz'  # XXX timepicker doesn't support 'ISO_8601'
     356        return 'HH:mm:ssZ'
    357357    if babel and locale:
    358358        values = {'h': 'h', 'hh': 'hh', 'H': 'H', 'HH': 'HH',
    359359                  'm': 'm', 'mm': 'mm', 's': 's', 'ss': 'ss'}
    def get_time_format_jquery_ui(locale):  
    375375def get_timezone_list_jquery_ui(t=None):
    376376    """Get timezone list for jQuery timepicker addon"""
     377    def utcoffset(tz, t):  # in minutes
     378        offset = t.astimezone(get_timezone(tz)).utcoffset()
     379        return offset.days * 24 * 60 + offset.seconds // 60
     380    def label(offset):
     381        if offset == 0:
     382            return 'Z'
     383        if offset < 0:
     384            offset = -offset
     385            sign = '-'
     386        else:
     387            sign = '+'
     388        return '%s%02d:%02d' % (sign, offset // 60, offset % 60)
    377389    t = datetime.now(utc) if t is None else utc.localize(t)
    378     zones = set(t.astimezone(get_timezone(tz)).strftime('%z')
    379                 for tz in all_timezones)
    380     return [{'value': 'Z', 'label': '+00:00'} \
    381             if zone == '+0000' else zone[:-2] + ':' + zone[-2:]
    382             for zone in sorted(zones, key=lambda tz: int(tz))]
     390    offsets = set(utcoffset(tz, t) for tz in all_timezones)
     391    return [{'value': offset, 'label': label(offset)}
     392            for offset in sorted(offsets)]
    384394def get_first_week_day_jquery_ui(req):
    385395    """Get first week day for jQuery date picker"""
  • trac/web/chrome.py

    diff --git a/trac/web/chrome.py b/trac/web/chrome.py
    index f5a7f0e8a..ac1731702 100644
    a b class Chrome(Component):  
    13791379            # default timezone must be included
    13801380            'timezone_list': get_timezone_list_jquery_ui()
    13811381                             if is_iso8601
    1382                              else [{'value': 'Z', 'label': '+00:00'}],
     1382                             else [{'value': 0, 'label': 'Z'}],
    13831383            'timezone_iso8601': is_iso8601,
    13841384        })
    13851385        add_script(req, 'common/js/jquery-ui-i18n.js')

comment:7 by Jun Omae, 7 years ago

Timezone examples of timepicker have the same issue….

comment:8 by Ryan J Ollos, 7 years ago

I hadn't noticed the issue with the timezone list being incorrect, displaying [object Object] for the utc entry. The patch seems to provide a minor improvement for editing the timepicker even for ISO8601 format. After the patch the cursor only moves to the end of the line when editing the timezone or entering an out-of-range value, such as 90 for the seconds field. Previously it would move the cursor to the end of the line on any edit. I made a new ticket for the issue: #12220.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae to the specified user.

Add Comment

E-mail address and name can be saved in the Preferences .
Note: See TracTickets for help on using tickets.