Edgewall Software
Modify

Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#13298 closed defect (fixed)

Autopreview triggers without a form change

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: normal Milestone: 1.2.6
Component: ticket system Version:
Severity: normal Keywords: autopreview
Cc: Branch:
Release Notes:

Fixed ticket autopreview triggering without a form change.

API Changes:
Internal Changes:

Description (last modified by Ryan J Ollos)

To reproduce:

  • Navigate to New Ticket. The Summary field will have focus.
  • Open a select box or put the focus on another element. Autopreview will trigger.

Screen Recording 2020-05-16 at 15.25.51 480p.mov

The problem is due to two changes:

  • In r13452 the workflow controls were added to the new ticket page. We added the create and assign action, which includes a select box for assigning the owner.
  • In r13707 the ticket_workflow.html template was added and the associated JavaScript was moved into this template. The JavaScript disables workflow inputs associated with actions that are not selected, such as the create and assign assign-to field. Since jQuery ready handlers executed in the order they are added, this JavaScript executes after autoSubmit initializes.

With the default workflow, create action will be selected when loading the New Ticket page.

The autoSubmit will initialize and collect a list of all inputs which will includes the #action_create_and_assign_reassign_owner select. After that happens, the #action_create_and_assign_reassign_owner select will be disabled.

Any of the events input cut paste keydown keypress change blur will trigger the autopreview, because the new array of form elements will be one-less in length than that which was originally stored (the one-less is the absence of the #action_create_and_assign_reassign_owner element.

I tried to solve this in several ways. First, by executing the JavaScript in ticket_workflow.html immediately after the elements are created rather than adding a document ready handler. This results in a flicker in which the element is shown for milliseconds without being disabled. Then, I tried hiding the entire form element until the JavaScript is executed, but it makes for complex code.

Another option would be to move the script block in ticket.html to the end of the page, so that the document ready handler is positioned after the one in ticket_workflow.html.

There appears to be a simpler solution. It looks like we can just initialize values on the first trigger, because we trigger on element losing focus (blur) as well as keydown, and values gets initialized before any elements of the form are changed.

  • trac/htdocs/js/auto_preview.js

    diff --git a/trac/htdocs/js/auto_preview.js b/trac/htdocs/js/auto_preview.js
    index a1dfd1bd9..e6e5f31bb 100644
    a b  
    2828    var timer = null;
    2929    var updating = false;
    3030    var queued = false;
     31    var values = null;
    3132
    3233    // Return true iff the values have changed
    3334    function values_changed(new_values) {
     
    8182
    8283    // Trigger a request after the given timeout
    8384    function trigger() {
     85      if (values === null)
     86        values = form.serializeArray();
    8487      if (!updating) {
    8588        if (timer)
    8689          clearTimeout(timer);
     
    9194      return true;
    9295    }
    9396
    94     var values = form.serializeArray();
    9597    // See #11510
    9698    return inputs.bind('input cut paste keydown keypress change blur',
    9799                       trigger);

Attachments (4)

Screen Shot 2020-05-16 at 15.03.45.jpg (34.1 KB ) - added by Ryan J Ollos 5 years ago.
Screen Shot 2020-05-16 at 15.06.43.jpg (29.6 KB ) - added by Ryan J Ollos 5 years ago.
Screen Shot 2020-05-16 at 15.15.19.jpg (14.7 KB ) - added by Ryan J Ollos 5 years ago.
Screen Recording 2020-05-16 at 15.25.51 480p.mov (1.3 MB ) - added by Ryan J Ollos 5 years ago.

Download all attachments as: .zip

Change History (10)

by Ryan J Ollos, 5 years ago

by Ryan J Ollos, 5 years ago

by Ryan J Ollos, 5 years ago

comment:1 by Ryan J Ollos, 5 years ago

Description: modified (diff)

comment:2 by Ryan J Ollos, 5 years ago

Description: modified (diff)

comment:3 by Ryan J Ollos, 5 years ago

Release Notes: modified (diff)

comment:4 by Ryan J Ollos, 5 years ago

Description: modified (diff)

comment:5 by Ryan J Ollos, 5 years ago

Resolution: fixed
Status: assignedclosed

Committed to 1.2-stable in r17349, merged in r17350, r17351.

comment:6 by Jun Omae, 4 years ago

#13317 is reported as a regression.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Ryan J Ollos 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.