#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 )
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 28 28 var timer = null; 29 29 var updating = false; 30 30 var queued = false; 31 var values = null; 31 32 32 33 // Return true iff the values have changed 33 34 function values_changed(new_values) { … … 81 82 82 83 // Trigger a request after the given timeout 83 84 function trigger() { 85 if (values === null) 86 values = form.serializeArray(); 84 87 if (!updating) { 85 88 if (timer) 86 89 clearTimeout(timer); … … 91 94 return true; 92 95 } 93 96 94 var values = form.serializeArray();95 97 // See #11510 96 98 return inputs.bind('input cut paste keydown keypress change blur', 97 99 trigger);
Attachments (4)
Change History (10)
by , 5 years ago
Attachment: | Screen Shot 2020-05-16 at 15.03.45.jpg added |
---|
by , 5 years ago
Attachment: | Screen Shot 2020-05-16 at 15.06.43.jpg added |
---|
by , 5 years ago
Attachment: | Screen Shot 2020-05-16 at 15.15.19.jpg added |
---|
comment:1 by , 5 years ago
Description: | modified (diff) |
---|
by , 5 years ago
Attachment: | Screen Recording 2020-05-16 at 15.25.51 480p.mov added |
---|
comment:2 by , 5 years ago
Description: | modified (diff) |
---|
comment:3 by , 5 years ago
Release Notes: | modified (diff) |
---|
comment:4 by , 5 years ago
Description: | modified (diff) |
---|
comment:5 by , 5 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Committed to 1.2-stable in r17349, merged in r17350, r17351.