Custom field dependencies

General discussion of Mantis.

Moderators: Developer, Contributor

Post Reply
Karzose
Posts: 2
Joined: 26 Oct 2005, 15:33

Custom field dependencies

Post by Karzose »

Is it possible to make one custom enumeration field dependent on the value selected in another? For example, if the user chooses "drinks" from the first enumeration, I would like the second to pripopulate
"milk|water|soda|juice|", but if they choose "food" in the first one, the second would show "steak|chicken|pasta|fish".

Any help would be appreciated.
kerthi
Posts: 17
Joined: 08 Nov 2005, 14:31

Post by kerthi »

I would also need such a behaviour!

did another post here: http://forums.mantisbt.org/viewtopic.php?t=924

Is that simply not possible, because none of these posts got any replies.

thx kerthi
vboctor
Site Admin
Posts: 1304
Joined: 13 Feb 2005, 22:11
Location: Redmond, Washington
Contact:

Post by vboctor »

Implementing such a feature is possible, but it complicates the implementation and definition of custom fields. The different approaches to implement this (assuming we are using custom functions to come up with the possible values) are:

- Javascript: using pure java script, for each possible value in the first combobox, we have to send the list. Hence, all the lists have to be sent to the page when it is loaded.

- AJAX: In this case when the first custom field is set, XmlHttpRequest call is done which retrieves the possible values for the second field. This technology is used in the filters used in recent versions of Mantis.

If someone volanteers to implement this, I can provide input into the approach to use and reviewing the code. My main aim would be achieving such flexibility without compilicating Mantis code or the way users interact or define custom fields.

Regards,
Victor
Checkout MantisConnect
http://www.futureware.biz/mantisconnect
kerthi
Posts: 17
Joined: 08 Nov 2005, 14:31

Post by kerthi »

Some thoughts.....

AJAX sheems like a promising approach on this.

The only question is how to set the values for the custom fields.

First one is no problem.
e.g first|second|third

when i select 'first' i want the second enum to get other values, then when selecting 'second'

But how to set these values for the second field, without changing the existing process of creating custom fileds?

|first_option1|first_option2|second_option1|second_option2......??

then it would be possible to select the values out of the DB with a statemant like this:

SELECT value_name WHERE value_name LIKE option_chosen%
(just writing pseudocode)

that would return first_option and second_option.

These select statement could be called via the xmlhttprequest updating the content of the second field.

errors in my idea? (sure there will be)
other ideas?

kerthi
vboctor
Site Admin
Posts: 1304
Joined: 13 Feb 2005, 22:11
Location: Redmond, Washington
Contact:

Post by vboctor »

See the following post on my blog:

Enumeration Custom Fields with Dynamic Possible Values
http://www.futureware.biz/blog/index.ph ... &tb=1&pb=1

Regards,
Victor
Subscribe to Mantis Blog
http://www.futureware.biz
kerthi
Posts: 17
Joined: 08 Nov 2005, 14:31

Post by kerthi »

yeah, clear so far.

But how to make the connection between two custom fields, one holding the top level categories, one the subcategories?
Narcissus
Developer
Posts: 338
Joined: 17 Feb 2005, 09:45

Post by Narcissus »

I've been thinking about the following as a way to implement this functionality.

Firstly, for the name of the custom field I would enter the names of all of the fields, each separated by a pipe. That way, it's just one custom field that happens to display multiple lists.

Then, in the values section, I would do a list in a textarea. For the following example, imagine that:
List 1 has three values 'A', 'B' and 'C'
List 2 has 12 values: 4 for each of List 1 and their values will be the current List 1 value, plus an 'A', 'B', 'C' or 'D' (that is 'AA', 'AB', 'AC', 'AD', 'BA', 'BB', 'BC', 'BD', 'CA', 'CB', 'CC' and 'CD').
List 3 has 24 values: 2 for each of the values in List 2 and their values will be the current List 2, plus an 'A' or 'B' (you can work out those values).

So, in my textarea I would write:
A
B
C

A|A
A|B
A|C
A|D
B|A
B|B
B|C
B|D
C|A
C|B
C|C
C|D

A|A|A
A|A|B
A|B|A
A|B|B
A|C|A
A|C|B
A|D|A
A|D|B
B|A|A
B|A|B
B|B|A
B|B|B
B|C|A
B|C|B
B|D|A
B|D|B
C|A|A
C|A|B
C|B|A
C|B|B
C|C|A
C|C|B
C|D|A
C|D|B

So basically you input a list of all of the variants and you can see from that list that, for example, when the first member is 'C' and the second member is 'B', then the third member is either 'A' or 'B'.

Having said all that, I would probably use a function to generate that list but still I think you can see where I'm going with it.

By storing and editing things in this manner, it comes closer to just a rendering issue than anything else...

Well, that's what I think, anyway!
Guest

Post by Guest »

I gave it a try and came up with the following silution. So far just a alpha *g*

1) i specify the custom fields that way:

Main Category = |cat1|cat2|cat3

Sub Category = |cat1_1|cat1_2|cat2_1|cat2_2|cat3_1|cat3_2

2) i make a realtion between the two

expanded the DB Table mantis_custom_field_table with the attribute child_of.
The Value of this field references to the parent field.

3) When rendering the Field, i generate a JS out of the above Information.

4) on the onchange event of the main Checkbox, i query the Sub Categories via AJAX.

Works so far, the only limitation is that the subcategories have to start with the name of the main category. Other issues are, that i modified some of the existing code directly (e.g. custom_field_api).


One more thing i need to do is to create a AJAX call when the bug_update_page is loaded, to make sure the right sub cateory is selected .

mfg kerthi
danich
Posts: 18
Joined: 21 May 2007, 17:39

Post by danich »

js or ajax will be needed for this as the report bug page is static.
Post Reply