#13317 closed defect (fixed)
Autopreview triggers only on second change (Regression after #13298)
Reported by: | Cinc-th | Owned by: | Ryan J Ollos |
---|---|---|---|
Priority: | low | Milestone: | 1.4.3 |
Component: | ticket system | Version: | 1.4.2 |
Severity: | normal | Keywords: | autopreview |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Fixed autopreview not triggering until second change when event attached to a select element. |
Description
The change in #13298 causes the following regression.
When using the autoSubmit() function in a custom script on the newticket page (see file refresh_actions.js in th:wiki/MultipleWorkflowPlugin) a request is only sent on second change of the select control with the attached autoSubmit handler.
This is because
- on the first change the variable values is null and will be initialized in trigger() with the current form data (this is after the change already happened)
// Trigger a request after the given timeout function trigger() { if (values === null) values = form.serializeArray(); ... }
- in request() called after the timeout the form is again serialized into variable new_values
- comparison of values and new_values yields no difference thus no request is sent.
The newticket page afaics currently works only by chance:
- Because the input control #field-summary has class trac-autofocus it will be activated on load.
- This means another control is losing focus
- The blur event is sent causing the function trigger() to be called and the variable values gets initialized before any change made by the user.
You may test this by removing the class trac-autofocus in ticket.html. Afterwards any first change to any select control will have no effect.
There is a workaround (see below) for plugin developers. Sorry, I don't have a solution right now for the problem.
Workaround
To solve the issue in the plugin I just send the blur event to the element with the attached autoSubmit() handler so values is properly initialized prior to any user input.
jQuery(document).ready(function(){ $("#field-type").autoSubmit({mw_refresh: '1', preview: '1'}, function(data, reply) { [...] }, "#action .trac-loading"); $("#field-type").blur() });
Attachments (1)
Change History (8)
by , 4 years ago
Attachment: | Screen Shot 2020-06-30 at 08.45.33.jpg added |
---|
comment:2 by , 4 years ago
I agree with comment:1. autoSubmit
isn't good for the use-case.
If the issue arises for appropriate use-cases of autoSubmit
we could trigger on the focus
event:
-
trac/htdocs/js/auto_preview.js
diff --git a/trac/htdocs/js/auto_preview.js b/trac/htdocs/js/auto_preview.js index 7ca558b71..38838d31e 100644
a b 95 95 } 96 96 97 97 // See #11510 98 return inputs.on('input cut paste keydown keypress change blur ', trigger);98 return inputs.on('input cut paste keydown keypress change blur focus', trigger); 99 99 }; 100 100 101 101 // Enable automatic previewing to <textarea> elements.
The values
would be initialized on focus, and the change
event will fire if the selection is changed.
comment:3 by , 4 years ago
Milestone: | next-stable-1.4.x → 1.4.3 |
---|
comment:4 by , 4 years ago
comment:5 by , 4 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:6 by , 4 years ago
Internal Changes: | modified (diff) |
---|
comment:7 by , 4 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fixed in r17465, merged in [17466:17467].
I don't consider that the plugin should use
$("#field-type").autoSubmit()
becauseautoSubmit()
doesn't fire when[trac] auto_preview_timeout
option or auto-preview timeout in user preferences is0
.Instead,
$("#field-type").on('click', ...)
should be used.