Dynamically change fields displayed when choose different taxonomy term

ssherriff - May 4, 2007 - 05:44
Project:Taxonomy Fields
Version:5.x-1.3-dev
Component:Code
Category:support request
Priority:normal
Assigned:boneless
Status:closed
Description

Hi,

I'm trying out your module for a site I'm working on. Basically I have a content type for 'Project'. This content type has a taxonomy called 'Project Type' where I have terms like Advertisement, CD Cover, DVD Cover, etc. Each type has mainly the same fields except a couple different here and there. For example, ad needs width and height, CD Cover needs how many pages in booklet, etc. I thought I would try this module out, but when I go to submit the type originally, it has all of the fields no matter what I choose as the Project Type. I'm not sure if this is correct behavior, or if the different fields are only supposed to be shown once content has been originally created, and then you go to edit. If so, how difficult is it to make it dynamic?

I really think being able to hide and display dynamically would be great. I'm a programmer and have done a few things with modules for drupal and might be able to help if this is something that could be done. If I can't get this working, I'm going to have to make a different content type for each, and that would add tons of extra work.

Cheers,
Steph

#1

boneless - May 4, 2007 - 11:34
Assigned to:Anonymous» boneless

Hi Steph,
as far as I can see taxonomy_fields should be able to help you.
Just to make this clear, if you want a field showing up only for a certain term, you don't need to add it to the content type but just assign it to the term on '?q=admin/content/taxonomy_fields', for example assign a 'width' field to the term 'ad'. If a field is assigned to the content type it will always show up, no matter what taxonomy_fields does.
Displaying the fields attached by taxonomy_fields dynamically seems a bit difficult to me. I thought about it, because I know, going back to the edit page after choosing a term is annoying. It could be solved by using AJAX to insert the fields automatically when a term is chosen, therefore the form created by taxonomx.module needs to be changed. I'll think about implementing this feauture in a later release but at the moment I just don't have the time.

Hope this helps you, don't hesitate to ask again if you have troubles.

#2

ssherriff - May 7, 2007 - 06:12

I've been thinking that maybe a multi-page form is a better way of going about it. Having a two step form where on the first page is where the taxonomy term is selected, and on the second is where the specific fields are set. The problem with this is it could get very complex if people wanted to have 3 or 4 step processes.

I may implement a possible rough solution with only a two step form and see how it goes. I'm a bit shaky with the Forms API and how to get the formid, but we'll see how I go.

#3

johsw - May 7, 2007 - 10:59
Title:Dynamically change fields displayed when choose different taxonomy term» +1

This sounds very interesting. I would really like to see either the multipage or even better the ajax-solution.

/J.

#4

Michelle - May 7, 2007 - 13:37
Title:+1» Dynamically change fields displayed when choose different taxonomy term

Restoring the title...

#5

smitty - June 12, 2007 - 14:05

Subscribing

#6

ssherriff - June 13, 2007 - 06:07

I haven't started working on this, but will fairly soon. This is for a graphic design company site, and we need to get the public part of the site out first, and then will work on the client area part of the site, which is what this would be for. I will be in touch once I can have a better look at this.

#7

hbfkf - June 25, 2007 - 10:29

Subscribing.

#8

noizyboy - August 2, 2007 - 04:09

subscribing. would love to see something like this working.

#9

boneless - August 6, 2007 - 04:33

update

developement in progress, just don't have too much time at the moment.
am a bit stuck with changing forms by javascript, might have to make up at totally new form each time a term is chosen.
suggestions and ideas appreciated.

#10

stephen.idealso - August 25, 2007 - 00:48
Assigned to:boneless» stephen.idealso

A way to do this was recently introduced to me. It will require some custom CSS and JavaScript work, but it should just do the trick.

What you'd want to do is specify a id to wrap around the fields that need to be turned on/off ... if you have multiple fields to turn on/off per taxonomy term you can choose, this may become tricky, but shouldn't be too much trouble. You could have a id in the CSS for each taxonomy option, for example if the taxonomy term is "red" you could have "red_on" and "red_off", then wrap "red_on" around each field that gets turned on with the selection of the term "red", and the same with "red_off" just in reverse.

The cool thing would be to add to a module the functionality of actually storing the essential variables for the custom CSS in the database for later retrieval, then having a function to dynamically build the CSS and append it to the CSS loaded by the site before the forms are built, then use a theme_hook of some type to wrap the CSS div's around each field as they become needed/appropriate.

The magic behind this idea is then some custom javascript to enable/disable view of the tags you wrapped around each field. it would essentially check for the change of the taxonomy select, then turn on the fields with if they aren't already on, and off the fields with if they aren't already off.

What would be even more cool is if you could then add some custom required checking or error checking, so that if the field is "turned on" you can have it required, but if it's "turned off" it may be required but the required check doesn't happen. This would be a bit more tricky, but would wrap this module up quite nicely.

If I had time to create a module that did this, I would; or I'd help add these functionally to the Taxonomy Fields module (though I think this is getting a bit outside the original scope of Taxonomy Fields, though a great bit of functionality). Due to my lack of time, I'm going to only ad a very small amount of this to my own project, leaving everything not required, but encouraged. The part that I'm a bit sad I will not be doing is adding the "create new taxonomy term" right inside the add content form, as this would really be nice and quick and easy, and would cut down click time for the user. But alas, it exponentially increases click time for me, the admin, so it doesn't get done until I have some spare time.

Hope this helps, sorry I droned on a bit, but as you can see it's very near and dear to my heart!

-S

P.S. ... sorry if this was posted in the wrong location, but I thought it was relevent. message me if it should go in another spot.

/================\
| Stephen Baker  |
|----------------|
| Ideal Solution |
|----------------|
| Software Dev.  |
\================/

#11

jiangxijay - November 1, 2007 - 01:05

Subscribe.

#12

streetdaddy - January 8, 2008 - 01:27

Subscribe.

#13

TheOnlyHarry - January 14, 2008 - 14:04

See http://drupal.org/project/conditional_fields for a similar module, including an implementation of dynamic forms but without the taxonomy functionality...

#14

scottrigby - February 3, 2008 - 02:41

Hi, This sounds really great -

i actually need this functionality now and am trying an insane workaround to get it to happen. ugh.

In the meantime, I'd use the conditional fields module, except it has a bug in IE 6&7 (sadly, a lot of users will be affected, so can't use till that gets settled)

Looking forward to working with this once it's implemented!

#15

boneless - February 9, 2008 - 03:47
Assigned to:stephen.idealso» boneless

hi all,

i am nearly done, most functionality is working already.
a new version will be released within 2 weeks.
thanks for your patience!

#16

baja_tz - February 13, 2008 - 17:53

subscribe

#17

Zach Harkey - February 26, 2008 - 06:02

subscribe

#18

josoal - March 8, 2008 - 18:21

subscribe

#19

josoal - March 12, 2008 - 19:09

I see new funcionality in 5.x-1.6dev

-#141285: Taxonomy fields are now dynamically added using AJAX. If removed they are positioned off screen, so entries into fields aren't deleted by accident. While the taxonomy fields are loading, an animated gif is displayed.

I´m testing it in a clean drupal 5.7 intall, and I don´t see AJAX add.

(Sorry for my english)

#20

boneless - March 13, 2008 - 00:32

Implemented in the new 1.6 version, check it out!

josoal, can you please put a detailled report into another thread?
Does the 'manage taxnonomy' menu work?
Is JavaScript enabled?

#21

josoal - March 13, 2008 - 09:39

http://drupal.org/node/233678
"Manage Taxonomy fields" work.
I have JavaScript enabled.

#22

boneless - March 27, 2008 - 06:16
Status:active» closed
 
 

Drupal is a registered trademark of Dries Buytaert.