Edgewall Software

Opened 2 years ago

Last modified 23 months ago

#13298 closed defect

Autopreview triggers without a form change — at Version 3

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 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 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. So I tried hiding the entire form element until the JavaScript is executed. It's a bit messy.

Or we could move the script block in ticket.html to the end of the page.

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;
    3233    // Return true iff the values have changed
    3334    function values_changed(new_values) {
    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    }
    94     var values = form.serializeArray();
    9597    // See #11510
    9698    return inputs.bind('input cut paste keydown keypress change blur',
    9799                       trigger);

Change History (7)

by Ryan J Ollos, 2 years ago

by Ryan J Ollos, 2 years ago

by Ryan J Ollos, 2 years ago

comment:1 by Ryan J Ollos, 2 years ago

Description: modified (diff)

comment:2 by Ryan J Ollos, 2 years ago

Description: modified (diff)

comment:3 by Ryan J Ollos, 2 years ago

Release Notes: modified (diff)
Note: See TracTickets for help on using tickets.