Edgewall Software
Modify

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#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)

Screen Shot 2020-06-30 at 08.45.33.jpg (81.7 KB ) - added by Ryan J Ollos 4 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by Jun Omae, 4 years ago

I don't consider that the plugin should use $("#field-type").autoSubmit() because autoSubmit() doesn't fire when [trac] auto_preview_timeout option or auto-preview timeout in user preferences is 0.

Instead, $("#field-type").on('click', ...) should be used.

Last edited 4 years ago by Jun Omae (previous) (diff)

by Ryan J Ollos, 4 years ago

comment:2 by Ryan J Ollos, 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  
    9595    }
    9696
    9797    // 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);
    9999  };
    100100
    101101  // Enable automatic previewing to <textarea> elements.

The values would be initialized on focus, and the change event will fire if the selection is changed.

Last edited 4 years ago by Ryan J Ollos (previous) (diff)

comment:3 by Ryan J Ollos, 4 years ago

Milestone: next-stable-1.4.x1.4.3

Moving to 1.4.3 to consider comment:2 change.

comment:4 by Cinc-th, 4 years ago

I tested the change from comment:2 with Trac 1.4.2.

It fixes the problem for the newticket page. Preview now properly works when CSS class trac-autofocus is not applied to any control.

comment:1 raises valid concerns. I'll revisit the plugin to address the problems.

comment:5 by Ryan J Ollos, 4 years ago

Owner: set to Ryan J Ollos
Status: newassigned

comment:6 by Ryan J Ollos, 4 years ago

Internal Changes: modified (diff)

comment:7 by Ryan J Ollos, 4 years ago

Resolution: fixed
Status: assignedclosed

Fixed in r17465, merged in [17466:17467].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.