Edgewall Software

Opened 21 months ago

Last modified 19 months ago

#13298 closed defect

Autopreview triggers without a form change — at Initial Version

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:
API Changes:
Internal Changes:


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.

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.
  • 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. 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.

Any of the events input cut paste keydown keypress change blur will trigger the callback, because the new array of form elements will be one-less than that which was originally stored.

No image ""Screen Shot 2020-05-16 at 15.06.43".jpg" attached to Ticket #13298

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, so 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 (3)

by Ryan J Ollos, 21 months ago

by Ryan J Ollos, 21 months ago

by Ryan J Ollos, 21 months ago

Note: See TracTickets for help on using tickets.