1

I'm working on a drupal project and part of it is a sort of "tile overview" page. Its a 3x? grid, with a variable length.
|--|--|--|
|--|--|--|
|--|--|--|
|--|--|--|
.. .. ..
Sort of like that, I hope you can tell what I'm trying to describe.
Each row of 3 is a field_collection. Now, each field can be either an image field or a text field. I want the user to be able to choose. How would I implement such a feature?
My solution as of now is to have 6 fields per row: one image field and one text field per each single field. Then the user would be told to only fill in one. If he fills in both, one of them gets ignored (php: isset() priority). Obviously this is far from optimal. What I'm looking for is like a radio button functionality so that when the user has a value set for one of the two possible field types, the other one gets disabled. Or just let the user decide first which he wants and then only display that one.
Help would be much appreciated.

  • You will either have to create this through a custom module (this won't be easy, nor short I think) or just add some JS magic to help you :) here's basic idea: upon page load, find the fields, insert a radio element (e.g. text/field), select default option, hide others, and upon activating the radio hide/show appropriate fields. This is the fastest solution. Hope it helps. – Aram Boyajyan Mar 9 '16 at 8:50
0

Check this module:

Conditional Fields

This module lets you to set things such a visibility, depending on other form elements.

It works based on Drupal's States API ( which you could also use in your custom module to achieve what you want )

  • I agree. The functionality provided would be hard to replicate. – Niall Murphy Mar 9 '16 at 9:47
  • Actually, I just ran into a new problem (should I open a new question for this?): I've set up a field_collection with 9 fields: 3 image fields, 3 text fields and 3 booleans that let the user choose if he wants an image or a text tile. I set up dependencies so that the image or text editors are only visible if the boolean is set to the correct value. It works fine for the first field_collection but when there are multiple field_collections (of the same type) in a content type then it won't work on the second and onwards. Is this a bug or am I doing something wrong? – luke Mar 9 '16 at 10:18
  • 1
    Found the solution: This patch adds functionality for multiple field_collection fields – luke Mar 9 '16 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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