Modify

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#12612 closed defect (fixed)

rules.js throws

Reported by: tero.isoaho@… Owned by: Ryan J Ollos
Priority: normal Component: DynamicFieldsPlugin
Severity: normal Keywords: AgiloForTracPlugin
Cc: Trac Release: 1.0

Description (last modified by Ryan J Ollos)

The plugin throws causing document ready functions to be not executed. At least with AgiloForTracPlugin this results to main navigation bar being missing.

The problem is at dynamicfieldsplugin/trunk/dynfields/htdocs/rules.js@15114:175#L175. input.attr is undefined and hence results into error; also seen in the browser console.

Original code:

  if (input.attr('id').slice(6) !== spec.trigger)
    return;

Patched:

  if (input.attr('id') === undefined || input.attr('id').slice(6) !== spec.trigger)
    return;

After patching the plugin works fine also with agilo for trac plugin.

Attachments (0)

Change History (10)

comment:1 Changed 9 years ago by Ryan J Ollos

Owner: changed from Rob Guttman to Ryan J Ollos
Status: newaccepted

Possibly related to [15114] / #12609, but I make no guarantees that the plugin will function with Agilo.

What is your [ticket-custom] section?

comment:2 Changed 9 years ago by Ryan J Ollos

Description: modified (diff)

comment:3 Changed 9 years ago by tero.isoaho@…

Agreed; seems to be related. Understood about agilo but seems to be working "ok" so far.

This basic ticket-custom from my sandbox environment replicates the problem. There are simply two "subcomponent" select boxes that are hidden or shown based on the type of the "component".

[ticket-custom]
businessvalue = select
businessvalue.label = Business Value
businessvalue.options = |100|200|300|500|800|1200|2000|3000
businessvalue.value = 
drp_resources = text
drp_resources.label = Resources
i_links = text
i_links.label = Referenced By
o_links = text
o_links.label = References
rd_points = select
rd_points.label = Story Points
rd_points.options = |0|1|2|3|5|8|13|20|40|100
remaining_time = text
remaining_time.label = Remaining Time
sprint = select
sprint.label = Sprint
sprint.value = 
story_priority = select
story_priority.label = Importance
story_priority.options = |Mandatory|Linear|Exciter
story_priority.value = 
subcompo1 = select
subcompo1.options = |test1|test2
subcompo1.order = 8
subcompo1.show_when_component = component1
subcompo2 = select
subcompo2.options = |tset1|tset2
subcompo2.order = 9
subcompo2.show_when_component = component2

comment:4 in reply to:  3 Changed 9 years ago by Ryan J Ollos

Replying to tero.isoaho@…:

This basic ticket-custom from my sandbox environment replicates the problem.

Have you been able to replicate the problem without Agilo installed? I'm not able to reproduce.

Could you please post the error from the console, including the stack trace?

comment:5 Changed 9 years ago by tero.isoaho@…

I currently have only the patched version of the plugin installed but I did some debugging. The real problem seems to be here where there are no input fields to attach the change event (like the agilo enabled main page). Here: dynamicfieldsplugin/trunk/dynfields/htdocs/dynfields.js@15114:78#L78

    // collect all input fields that trigger rules
    $.each(triggers, function (trigger, specs) {
      var input = $(specs.selector).get(0);
      inputs.push(input);
    });
    inputs = $.unique(inputs);

    // attach change event to each input and trigger first change
    $.each(inputs, function (obj) {
      $(this).change(apply_rules).change();
    });

While there are no input fields it still tries to attach apply_rules to change event and then trigger the change(). inputs array contents are [ undefined ]. Stack trace at the offending line is like this:

hiderule.apply(i=0, spec=Object { clear_on_hide="true", hide_always="false", link_to_show="false", more...})rules.js (line 175)
window.apply_rules/</<(a=[Object { clear_on_hide="true", hide_always="false", link_to_show="false", more...}, Object { clear_on_hide="true", hide_always="false", link_to_show="false", more...}], c=function(i, spec), d=undefined)dynfields.js (line 37)
f</<.each(trigger="component", specs=[Object { clear_on_hide="true", hide_always="false", link_to_show="false", more...}, Object { clear_on_hide="true", hide_always="false", link_to_show="false", more...}])jquery.js (line 2)
window.apply_rules/<()dynfields.js (line 36)
f</<.each()jquery.js (line 2)
window.apply_rules()dynfields.js (line 35)
f.event.dispatch()jquery.js (line 3)
f.event.add/i()jquery.js (line 3)
f.event.trigger()jquery.js (line 3)
.trigger/<()jquery.js (line 3)
f</<.each()jquery.js (line 2)
f</e.prototype.each()jquery.js (line 2)
.trigger()jquery.js (line 3)
f.fn[b]()jquery.js (line 3)
dynfields.js()dynfields.js (line 82)
f</<.each()jquery.js (line 2)
dynfields.js()dynfields.js (line 81)
f.Callbacks/o()jquery.js (line 2)
f.Callbacks/p.fireWith()jquery.js (line 2)
f</<.ready()jquery.js (line 2)
f</B()jquery.js (line 2)
dynfields.js()dynfields.js (line 81)
f.Callbacks/o()jquery.js (line 2)
f.Callbacks/p.fireWith()jquery.js (line 2)
f</<.ready()jquery.js (line 2)
f</B()

Console for the non-patched plugin says that cannot call slice() on 'undefined' on the non-patched offending line (dynamicfieldsplugin/trunk/dynfields/htdocs/rules.js@15114:175#L175).

And yes, input.attr('id') is indeed undefined. input is Object [ Window sandbox ], i.e. the main window which is the case for example when loading the main wiki page. It is not specific to agilo; happens also with vanilla trac.

Is it so that on vanilla trac there happens to be no more document.ready functions to be executed so the bug remains hidden? I tried the plugin with a vanilla trac installation and undefined input.attr('id') exists there also but no visible harm is done unless there is another plugin which expects its document ready() to be called.

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

comment:6 in reply to:  5 ; Changed 9 years ago by Ryan J Ollos

Replying to tero.isoaho@…:

I tried the plugin with a vanilla trac installation and undefined input.attr('id') exists there also but no visible harm is done unless there is another plugin which expects its document ready() to be called.

What was the context in which you reproduced the issue with Trac? Did the user not have TICKET_MODIFY?

comment:7 in reply to:  6 Changed 9 years ago by tero.isoaho@…

Replying to rjollos:

What was the context in which you reproduced the issue with Trac? Did the user not have TICKET_MODIFY?

When loading the main wiki page. Yes, user was logged in and has basically all permissions == TRAC_ADMIN.

comment:8 Changed 9 years ago by Ryan J Ollos

The error occurring in the wiki relam is an important detail which wasn't obvious in your earlier comment. This is a regression in [15057].

comment:9 Changed 9 years ago by Ryan J Ollos

Resolution: fixed
Status: acceptedclosed

In 15124:

2.2.0dev: Fix regression in [15057]

Scripts and stylesheet should only be added for the query,
ticket and newticket realms.

Fixes #12612.

comment:10 Changed 9 years ago by tero.isoaho@…

Thanks, a sensible fix. :-)

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

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.