In saved node the filtered field is just blank

Comments

Budrick’s picture

StatusFileSize
new8.81 KB

Ive found that Drupal, would not accept values which were not included in $form array.

Also I did some changes to adopt module for my needs.
On my computer JS worked very slow - it took several seconds to refresh filtered field after changing filtering field (660 records car make/model list).
Also there were some problems with my own javascript - because every time filtered field were completely removed and recreated, therefore all references to the field were lost.

I changed the structure of JS array (in php), and optimised JS file.
Attaching changed module, maybe someone can find it usefull.

Budrick’s picture

StatusFileSize
new8.81 KB

Ive found that Drupal, would not accept values which were not included in $form array.

Also I did some changes to adopt module for my needs.
On my computer JS worked very slow - it took several seconds to refresh filtered field after changing filtering field (660 records car make/model list).
Also there were some problems with my own javascript - because every time filtered field were completely removed and recreated, therefore all references to the field were lost.

I changed the structure of JS array (in php), and optimised JS file.
Attaching changed module, maybe someone can find it usefull.

Budrick’s picture

StatusFileSize
new1.08 KB

I missed setting the default value.

pancho’s picture

For me the autoselect doesn't seem to work with or without Budrick's changes...

On the content type config everything's all right:
In the slave field I selected the correct master field and added the following entries to the "allowed values list":

Test
Café Schmitz, Worms
Lincoln Theater, Worms
SAP-Arena, Mannheim

When I now create a node:
- No matter what I select in the master field, I see all entries in the slave field.
- The slave field gets lost when saving the node.

Did I do something wrong or what might be the problem?

Budrick’s picture

StatusFileSize
new9.01 KB

I dont know why slave field is getting lost.
To fix this I just added this function to dependantDropdown.module:

function dependantDropdown_nodeapi(&$node, $op, $a3, $a4){
  if ($node->type != 'car') return; //change 'car' to your nodetype
  switch($op){
    case "submit": $node->field_model[0]['value'] = $_REQUEST['field_model']['keys']; //change field_model to your slave field name
    break;
  }
}

What JS error are you getting when changing master field?
In my case jquery.js were not loading. To fix this add:

      drupal_add_js('misc/jquery.js', 'core');
after line
drupal_add_js($path . '/dependantDropdown.js');

Also try use no spaces in values list.

pancho’s picture

Thanks for following up!

Your question: I didn't get any JS error because there was no JS action fired at all, though jquery.js was already loaded. The space characters were not the problem either. And not even your method "dependantDropdown_nodeapi" helps - the value in field2 is still not being saved... :(

Additionally I figured out the following separate problems:

  1. Two fields (field1->field2) on one page are okay, but not more. With field1->field2->field3 no filter is applied at all. With field1->field2 and field3->field4 on the same page only the latter works.
  2. Suppose there is an option ("lexus") in field1 without a corresponding sub-option in field2:
    FIELD1:
    toyota
    nissan
    lexus
    FIELD2:
    toyota,camry
    toyota,corolla
    nissan,primera

    I now create a node. Everything works fine as long as I select "toyota" or "nissan" in field1. When I select "lexus", I'm of course presented no sub-options in field2 (which is correct). Now, if I switch back e.g. to "toyota", the selector remains empty until I reload the page.

  3. The label can not be set explicitely as in the regular select list. key|label is interpreted altogether as the key.
  4. Key and filtervalue must be separated just by a comma and not by comma and space (, ). Might be by design but is too errorprone.

If you can reproduce those errors, I will create separate issues for them.

Budrick’s picture

If no JS action is fired, then body.onload might have been redefined by some other js code.
What about empty field - is it present in $_REQUEST if you print_r it?

And I nefer tried several fields or filters with no values in filtering field.
The module is rather raw, but at leas I've made it work for me.

green monkey’s picture

Drupal 5 - DDD V5 Beta

ouch .... Greetings all,

I have been trying to understand the prpoer setup for this module all day. I'm just not getting something right. Would someone mind offering a little advice?

Here's what I have to work with:

State: field_state
County: field_county

I set-up "State" as a Select List

with Allowed values list: (like this - example is shorter ver of course)
Alaska
Arizona
Arkansas
California
Colorado

Then I setup "County" as an Active Select

with Allowed values list: (like this - example is shorter ver of course)

Alaska,Adams
Alaska,Asotin
Alaska,Benton
Alaska,Chelan
Alaska,Clallam
Alaska,Clark
Alaska,Columbia
Alaska,Cowlitz

aqll that comes up for a choice in "County" is Alaska

what am I not doing correctly?

thanks
J

Budrick’s picture

Just invert your list:

Adams,Alaska
Asotin,Alaska
...

green monkey’s picture

thank you for your reply, I just can't get this to work and I can't figure out what I'm not doing correctly

I tired your post above, but its not working

I'm using 4.7 now - to see if I can get that to work

here's what I'm doing

field1 = field_one and is "Select List"
field2 = field_two and is "Active Select"

(field1 values)
one
two

(field2 values)
red,one
blue,one
green,two
yellow,two

It doens't matter if I select "one'" or "two" from field1 Select List,

I still see all choices for field2

firefox did trap an error for though

Error: Drupal is not defined
Source File: http://www.mywebsite.com/modules/dependantDropdown/dependantDropdown.js
Line: 55

I greatly appericate your help on this - it looks so simple - yet.............

Budrick’s picture

Try to add drupal.js, jquery.js.
Look for "drupal_add_js" above

f.mardini’s picture

hi,
I just can't seem to get it to work
The slave list contains all values and is not being updated on changes to the filtering list.
My set up is like this: Drupal 5 with latest dependantDropdown

Country (a select list with text values) with allowed values
France
Germany
Italy
etc.

City (an active select list)
filter according to field country,
allowed values:
Pairs,France
Berlin,Germany
Rome,Italy
etc.

thanks a lot

Budrick’s picture

Filter according to:
If the name of the master field is "country" it should be "field_country", if "Country" it should be "field_Country" etc.

What js error are you getting on page load, on master field change?
Did you try to add drupal.js, jquery.js as described above?

f.mardini’s picture

Hi,
Thanks.
I included the javascript files as described above.
When i set the filter according to field set to field_country i get the following error: filteredField has no properties (caught by firebug).
When set to field_Country i get no errors but also no results :( the list does not change.

jsm174’s picture

I was finally able to get this to work. I too was getting the filteredField javascript error. If your using Drupal 5.1, replace the dependantDropdown module with the attached version attached in message #5.

I believe the link is: http://drupal.org/files/issues/dependantDropdown_1.zip

I have a Select List field called field_series with allowed values list set to:
100|100
200|200
300|300
400|400
600|600
700|700

I then have a Active Select List field called field_models with allowed values list set to:
148W,100
152W,100
146W,100
155W,100
158W,100
260XW,200
257T,200
E361T, 300
361, 300
N361TL,300

Allowed values lists "Active Select List"s do not accept the pipe (|). So you can't use 148W|148W,100

Hope that helps,
-- Jason

laryn’s picture

I am getting this error when I try to use the file linked above and set up an Active Select based on a Select List:

Error: missing ] after element list
Source File: http://localhost/?q=node/add/contentitemname
Line: 150, Column: 151
Source Code:
var js_options={'Mac':['eMac','iBook','iMac-G3','iMac-G4','iMac-G5','iMac-Intel','PowerMac-G5','PowerBook-G4','MacBook-Intel','MacPro-Intel','Help-Don't Know'],

pushkar’s picture

Any help here?

Does it work for anyone? Developers- are you there? Please help!

pushkar’s picture

Title: Empty field in saved node » Empty field in saved node : renewed interest.

Ok, so here is one 'bug' i think I found. I am using the standard STATE / CITY example with the following data set
- a Select List field called field_state with allowed values list set to:
100|100
200|200
300|300
400|400
600|600
700|700

I then have a Active Select List field called field_city with allowed values list set to:
148W,100
152W,100
146W,100
155W,100
158W,100
260XW,200
257T,200
E361T, 300
361, 300
N361TL,300

Allowed values lists "Active Select List"s do not accept the pipe (|). So you can't use 148W|148W,100
(borrowed from http://drupal.org/node/106401, commend #15)

In dependentDropdown.js, line 4 (the firebug catch),

	var filteredField = document.getElementById("edit-"+filteredFieldName</strong>+"-keys");

I replaced it by (temporarily)

	var filteredField = document.getElementById("edit-field-city-keys");

Notice that the value of filteredFieldName is field_city but the CSS has the element as field-city (with hyphen instead of underscore).

With this hack, I am able to save the options correctly (yay!). Of course this is specific. but may be this helps generate some interest and leads.

In addition, I think for the most part its a Javascript issue now. If someone can help write the parsing of the arrays and depdendt lists, we should be on the homestretch pretty soon.

pushkar’s picture

Title: Empty field in saved node : renewed interest. » Empty field in saved node : Bounty

http://pushkar.chipin.com/drupal-dependent-dropdown-module

Chipin please!

note: I have limited skills. This is to get the bounty rolling for the first person who solves the problems and makes the module work for drupal 5.1 and drupal 4.7 AND RELEASES THE CODE FOR EVERYONE.

You cant see my $10 because i cant pay myself through paypal. But I will add it when I pay the bounty.

vanvemden’s picture

It wasn't working for me and then I set the filtering field (in the example of pushkar field_state) to required in Content Management and guess what ... it worked!
Even without the

 var filteredField = document.getElementById("edit-field-city-keys");

hack. Hope this helps somebody.

vanvemden’s picture

What I forgot to mention at comment #20 was that I used the module downloaded from comment #15.

sdsheridan’s picture

Priority: Normal » Critical

I'm still having problems with this. I have the DDD working in the country-state scenario on a node-profile, but nothing is being saved back to the CCK table --- the column value is NULL. How did those who got this working get it to save back to the table?

If I can't get this working (or even if I can), I'm wondering if anyone has figured out another way to do this kind of dependent sub-select thing.