Modify

Opened 14 years ago

Last modified 12 years ago

#8082 reopened defect

Using "component" as parent of chained fields resets value on modify

Reported by: afrogamer@… Owned by: Richard Liao
Priority: low Component: TracTicketChainedFieldsPlugin
Severity: minor Keywords:
Cc: Trac Release: 0.11

Description

I have "component" set as the parent field for my custom chained fields. When I go to edit a ticket, the value in the component field is the default value, and I have to change this back to the correct one manually to avoid changing the ticket's component.

Attachments (1)

tcf_ticket.js (6.0 KB) - added by mb@… 13 years ago.
Patched JavaScript

Download all attachments as: .zip

Change History (15)

comment:1 Changed 13 years ago by anonymous

I have this bug also, it seems to be because tcf_orig_values is only populated if the original field is an input element.

comment:2 Changed 13 years ago by anonymous

I changed line 14 of tcf_ticket.js from

selector_inputs.push("input#field-" + field);

to

selector_inputs.push("#field-" + field);

And now it works fine.

comment:3 Changed 13 years ago by cabbiepete@…

Forgot to add my email on the last post. Could you notify me if/when this gets checked in also and I'll update and retest?

comment:4 Changed 13 years ago by Richard Liao

Resolution: fixed
Status: newclosed

Fixed in [9928]

comment:5 Changed 13 years ago by cabbiepete@…

Resolution: fixed
Status: closedreopened

Have tried the new version and the change made (which isn't the one above) does not fix the issue. If I redo the change above on the new version it does fix the issue.

My trac.ini looks like this (relevant part)

[tcf] chained_fields = component, subcomponent hide_empty_fields = false

I have a custom field 'subcomponent' that was already a select (the issue even after the fix) and my json for chained fields is.

{
	"component":{
		"Core Media":{
			"subcomponent":{
				"Multiple":{},
				"DC":{},
				"Encoder":{},
				"ImageConvertor":{},
				"LiveState":{},
				"PBX":{},
				"Podcast":{},
				"MZAdapter":{},
				"SlideConvertor":{},
				"Transcode":{}
			}
		},
		"Core Platform":{
			"subcomponent":{
				"Multiple":{},
				"Booking":{},
				"Campaign":{},
				"Channel":{},
				"ChannelOwnerReport":{},
				"Communication":{},
				"Community":{},
				"DC":{},
				"Email":{},
				"Enquiry":{},
				"Feedback":{},
				"Question":{},
				"Search":{},
				"Slide":{},
				"Summit":{},
				"Survey":{},
				"Track":{},
				"Vote":{}
			}
		},
		"Data Migration":{"subcomponent":{"N/A":{}}},
		"Don't Know":{"subcomponent":{"N/A":{}}},
		"Flash":{
			"subcomponent":{
				"Multiple":{},
				"FlashPresenter":{},
				"FlashViewer":{},
				"Widget":{}
			}
		},
		"Framework":{"subcomponent":{}},
		"Infrastructure":{"subcomponent":{}},
		"Integration and Reporting":{
			"subcomponent":{
				"Multiple":{},
				"Notification":{},
				"Report":{},
				"User":{}
			}
		},
		"Multiple":{"subcomponent":{"N/A":{}}},
		"Portal":{
			"subcomponent":{
				"Multiple":{},
				"Content":{},
				"Portal":{},
				"OpsSite":{}
			}
		}
	}
}

comment:6 Changed 13 years ago by Richard Liao

I have not such problem in my environment, trac 0.12.1. Which trac version are you using?

BTW:

I have a custom field 'subcomponent' that was already a select

This field has no need to be select, use text is enough, since select fields will be verified by trac that only allow values in field's available options.

comment:7 Changed 13 years ago by cabbiepete@…

Trac version 0.11, sorry thought the Trac Release field indicated that already.

comment:8 in reply to:  6 Changed 13 years ago by cabbiepete@…

And this time a proper reply.

Replying to richard:

I have not such problem in my environment, trac 0.12.1. Which trac version are you using?

0.11

BTW:

I have a custom field 'subcomponent' that was already a select

This field has no need to be select, use text is enough, since select fields will be verified by trac that only allow values in field's available options.

Sure there is no need for select but it's what we had already and there isn't really a need to restrict the plugin to text fields only is there?

comment:9 Changed 13 years ago by mb@…

I have this bug as well. I figured out following issues in the tcf_ticket.js:

  • the root field always gets filled properly, as its value is handled by the code in line 98ff: for (var field in tcf_define) {...
  • all sub fields are filled by the tcf_orig_values variable which is set only for INPUT elements in line 27ff. Original values of SELECT elements are not retrieved at all and so they are not selected initially.

I got caught by this bug by having a custom tcf_product field as root field and trying to bind the component and version fields (which are naturally SELECT elements!) to the tcf_product field.

This might be the reason why some people are not troubled by the the problem :-)

Changed 13 years ago by mb@…

Attachment: tcf_ticket.js added

Patched JavaScript

comment:10 Changed 13 years ago by anonymous

Puuh - that thing quiet caused me having some headaches ;-)

But I can provide a solution right now. There were three problems mixing up in my environment:

  • Firefox 3.6 + 4.0
  • Trac 0.12.2 @ JQuery 1.4.2
  • JQuery UI 1.7.2 (doesn't know if that matters)

1) Originial values were not be collected for SELECT field. So I changed:

 27: $(field_selector_input + "," + field_selector_select).each(function(){

2) JQuery sorted the sources for .each calls in my case. As I defined a chain tcf_product --> version + component the component was filled up with original value first and got cleand againg by the change handler when tcf_product was filled later on. So I introduced keep to the original order in 140ff (I didn't use JQeury before so I do not know if there is a more elegant way to stay in natural order)

 140: for (var field=0; field<selector_selects.length; field++) {
 141: $(selector_selects[field]).each(function(){
   ...
 161: }

3) Assigning values via

 options[val] = null;

did not create an entry. So I changed this to

 148: options[val] = 1;

Greetings Markus

comment:11 in reply to:  10 ; Changed 13 years ago by Christian Masopust

Replying to anonymous:

Puuh - that thing quiet caused me having some headaches ;-)

But I can provide a solution right now. There were three problems mixing up in my environment:

  • Firefox 3.6 + 4.0
  • Trac 0.12.2 @ JQuery 1.4.2
  • JQuery UI 1.7.2 (doesn't know if that matters)

1) Originial values were not be collected for SELECT field. So I changed:

 27: $(field_selector_input + "," + field_selector_select).each(function(){

2) JQuery sorted the sources for .each calls in my case. As I defined a chain tcf_product --> version + component the component was filled up with original value first and got cleand againg by the change handler when tcf_product was filled later on. So I introduced keep to the original order in 140ff (I didn't use JQeury before so I do not know if there is a more elegant way to stay in natural order)

 140: for (var field=0; field<selector_selects.length; field++) {
 141: $(selector_selects[field]).each(function(){
   ...
 161: }

3) Assigning values via

 options[val] = null;

did not create an entry. So I changed this to

 148: options[val] = 1;

Greetings Markus

Hello Markus,

have tried you patch and it works for me.... in Firefox but not in IE8 !!

When using IE8 and changing a "tcf_..." select, the chained select (in my case "component") gets unusable, I cannot select or open the dropdown.

I've seen you're using jQuery 1.7.2... probably that DOES matter... how do you change the plugin to use an other version of jQuery than the installed (with Trac) version 1.4.2?

Thanks, Christian

comment:12 in reply to:  11 Changed 13 years ago by Christian Masopust

Could fix this by simple by applying the following simple patch to tcf_ticket.js... don't ask me why it now works also in IE :-)

  • tcf_ticket.

    old new  
    7373                var target_field = target["target_field"];
    7474                var target_options = target["target_options"];
    7575
    76                 $("#field-" + target_field).hide();
    7776                $("#field-" + target_field).empty();
    7877                for (var i=0; i<target_options.length; i++){
    7978                    var field_option = target_options[i];

comment:13 Changed 12 years ago by anonymous

I've tried to patch the tcf_ticket.js using patch. But everytime the file is restored to the old one. Any ideas what i'm doing wrong?

cd /data/trac/eggs/TracTicketChainedFields-0.1-py2.7.egg-tmp/tcf/htdocs/
diff -crB /data/trac/eggs/TracTicketChainedFields-0.1-py2.7.egg-tmp/tcf/htdocs/ Tb02 > Tb02.patch > /home/root/tcf_ticket.new.patch
patch -p2 -i /home/root/tcf_ticket/tcf_ticket.new.patch

comment:14 Changed 12 years ago by anonymous

Priority: normallow
Severity: normalminor

Modify Ticket

Change Properties
Set your email in Preferences
Action
as reopened The owner will remain Richard Liao.

Add Comment


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

 
Note: See TracTickets for help on using tickets.