0

My problem is that I want to add a drop down list to a node that selects an entity from that node based on its name, and display it. I am wondering if there is a module that does that; if there isn't, what the best approach is.

So far, I can only think of creating a custom node template to display the entities using JavaScript.

Unless I am mistaken, the Entity reference module won't work in my case; if it does, please clarify.

I have 4 tables in a single node; each table represents a week in a month. I want just a simple drop down list to select which week to display, and display that week's table.

1

2 Answers 2

3

Checkout the Entity reference module.

Provides a field type that can reference arbitrary entities.

5
  • this will not work with my case
    – Sari
    Commented Mar 10, 2013 at 9:18
  • Why won't this work? This is the defacto standard for referencing one node from another.
    – mpdonadio
    Commented Mar 11, 2013 at 11:08
  • @MPD I am not referencing a node from another node I just want to hide and show entities in the node view based on a select list
    – Sari
    Commented Mar 11, 2013 at 11:28
  • @Sari Actaully, this is how you would build out the content type. You would add in your entity refs, configure the display (probably want rendered entity, and then write some custom JS to make your select work.
    – mpdonadio
    Commented Mar 11, 2013 at 19:10
  • @MPD Why would I use reference to reference entities from the same node and then add JS to hide the not selected entities when I can add a select list in the template or using node_view and add the same JS to it.
    – Sari
    Commented Mar 12, 2013 at 7:58
0

seems no one can answer so I did what I first thought of for the sake of documentation

I added this to my node template node--NODENAME.tpl.php

<?php drupal_add_js('sites/all/themes/MYTHEME/scripts/scripts.js');?>
    <select id='showmethemoney'>
        <option selected="selected" value="field-name-field-week1">week1</option>
        <option value="field-name-field-week2">week2</option>
        <option value="field-name-field-week3">week3</option>
        <option value="field-name-field-week4">week4</option>
    </select>
    <?php
      hide($content['comments']);
      hide($content['links']);
      print render($content['field_week1']);
      print render($content['field_week2']);
      print render($content['field_week3']);
      print render($content['field_week4']);
      print render($content);
    ?>

and Created a js file "sites/all/themes/MYTHEME/scripts/scripts.js" with the following code :

(function ($) {
Drupal.behaviors.MYTHEME = {
attach: function(context, settings) {

 $(function() {
        $('#showmethemoney').change(function(){
            $('.field-type-text').hide();
            $('.' + $(this).val()).show();
        })
     .change();
    });

}
};
}(jQuery));  

this will show the selected field by default and will display the field I want from the select list

thanks for your time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.