Opened 4 years ago
Last modified 3 years ago
#13317 closed defect
Autopreview triggers only on second change (Regression after #13298) — at Initial Version
Reported by: | Cinc-th | Owned by: | |
---|---|---|---|
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: |
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() });