Opened 6 years ago

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

Reported by: Owned by: afrogamer@… richard low TracTicketChainedFieldsPlugin minor 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.

### comment:1 Changed 6 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 6 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 6 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 6 years ago by richard

• Resolution set to fixed
• Status changed from new to closed

Fixed in [9928]

### comment:5 Changed 6 years ago by cabbiepete@…

• Resolution fixed deleted
• Status changed from closed to reopened

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":{},
"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":{},
"Report":{},
"User":{}
}
},
"Multiple":{"subcomponent":{"N/A":{}}},
"Portal":{
"subcomponent":{
"Multiple":{},
"Content":{},
"Portal":{},
"OpsSite":{}
}
}
}
}


### comment:6 follow-up: ↓ 8 Changed 6 years ago by richard

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 6 years ago by cabbiepete@…

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

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

And this time a proper reply.

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 6 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 6 years ago by mb@…

Patched JavaScript

### comment:10 follow-up: ↓ 11 Changed 6 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 ; follow-up: ↓ 12 Changed 5 years ago by ChristianM

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 5 years ago by ChristianM

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 var target_field = target["target_field"]; var target_options = target["target_options"]; $("#field-" + target_field).hide();$("#field-" + target_field).empty(); for (var i=0; i

### comment:13 Changed 5 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 4 years ago by anonymous

• Priority changed from normal to low
• Severity changed from normal to minor