Hello. I have three content types:
Category

  • title
  • body

SubCategory

  • title
  • nodereference to Category
  • body

Products

  • title
  • nodereference to Category
  • nodereference to SubCategory
  • body

When I create a new node of type 'Products', I have to select one Category and one SubCategory. The question is how could I dynamically filter SubCategory with the category selected in the prior field?
I think It must be done with AHAHA, but I don't know where could I put the code to do it and how to do it?
Any suggestion?
Thanks.

Comments

jan_v’s picture

With node reference, you have the possibility to use a view to display the possible items. This option also provides an argument field. I haven't used this argument field before, but it might be possible to populate it with the selected category.

If it's possible to populate the argument field with another cck value in the same node, your problem is solved. I will do some research about this as well. I'll let you know if i find something.

briantes’s picture

Hello. Thanks for your answer but the problem is those arguments are static, that is, you can put a value when you create the field, but It can't be changed when creating 'products' node.
I have done some changes to cck nodereference to let 'php arguments', but It can't solve the problem.
Because I need to change it without reload the page, I need to do it in AHAHA or AJAX to change the view.

briantes’s picture

Hi. I change the answer.
Is there any way to add some javascript code associated to a ckk field?

jan_v’s picture

Haven't tried it before, but this might work:
in your template.php file, add this:


<?php
function themeName_preprocess_page(&$vars, $hook) {
  if ((arg(0) == 'node') && (arg(1) == 'add' || arg(1) == 'edit')) {
    drupal_add_js('sites/all/themes/mytheme/script.js');
  }
}
?>

replace "themeName" with your theme name, and the path with your script's path.

This code should add a custom js file in the section of your node/add and node/edit pages
Be sure to clear cache and rebuild theme registry

dogboy72’s picture

I had a similar problem - not exactly the same - #780630: How to use views_arg_context in a multireferential manner?
This module may be what you are looking for: http://drupal.org/project/hierarchical_select

briantes’s picture

After some months of search and try-error, I can't do it.
Someone could help me?
When adding/editing a new node, How could I filter the second cck field (subcategory) with the value selected in a prior field (categories)?

dogboy72’s picture

briantes’s picture

Thank you very much.
That's what I need