2

I have 2 content types, lets say A and B. There is field collection item in content type A (in which unlimited values could be added). User adds data in this field as he creates new content.

I want all those field collection options filled by user in A to appear as a select list while submitting content type B.

I create an entity reference field in content type B and tried to display all options of field collection item from A. It shows perfectly as I tested it in view.

Issue:

  • If I select to display all values in a single row, it shows all options in one row of select list.
  • I actually want to display each option in separate row, but it shows only the last item.

Anyone knows the solution?

Here are Settings of my View:

enter image description here

And this is my Field Setting:

enter image description here

As you can see, in View it shows both option. But in select list it shows only last option or all options in single row (by changing setting).

  • I believe you are using views to display that as you mentioned. Now did you try the option of showing each field in a separate row? By default all your field collection will be shown in one row as a one field, but there is a option, where views treat each field of field collection as separate row, Are you looking for that? – CodeNext Oct 21 '16 at 16:12
  • @CodeNext in content type B, I created a field of Entity Reference type and referred it to an Entity Reference View. That Entity reference view fetch values correctly, but on displaying those options as select list in my field, the issue occurs. – arsalan Oct 22 '16 at 6:21
3

This is a partial answer, looking for further guidance!

After a lot of exploration, I still couldn't find exact solution to my question.

While searching I found this topic titled: Entity Reference view to populate select list for reference field => only one result when using a contextual filter, might help others. This is a long node addressing similar problem.

But my problem was not solved by above mentioned link. So I used hook_form_alter,

function module_form_alter(&$form, &$form_state, $form_id){
    if($form_id == 'your_form_id'){
        $url_arg=arg(); //get arguments from URL
        $node_id=$url_arg[1];
        $node=node_load($node_id); //load appropriate node of Content type A
        $info = field_info_field('field_testing_code'); //load field from Content Type B's form
        $values = &$info['settings']['allowed_values']; //get list of allowed values
        $values= array(); //remove all existing values
        $i=0;
        while($node->field_consignment_text_field[und][$i][value]){
            $values[$node->field_consignment_text_field[und][$i][value]] = $node->field_consignment_text_field[und][$i][value];
            $i++;
        }
    field_update_field($info);
  }
}

As I mentioned, each B content type is a sub part of A content type. And URL contains id of A. When I open content type B's creation form one at a time, it works fine. When I open more that one forms having different A parent, form_alter shuffles data e.g Field data of tab 1 gets assigned to tab 2.This is the issue now. Looking for some solution for this.

| improve this answer | |
2

In a setting of of that particular field, there is a option under title of,

MULTIPLE FIELD SETTING,

Where there is a option of Display all values in the same row. Now suppose in my case this is the field collection filed (FC101 is a entire filed), Now if I check this option is will show entire field collection as a one field, on the otehr hand if, I uncheck this option the field in field collection are treated as they are in their own row. Now you can check the setting of of your field which is fetching this data in view, whether this option is there on not.

Just to explain properly I am describing this in answer, If this is not what you are looking for please let know, I will delete answer.

So, whatever field

enter image description here

| improve this answer | |
  • Yes I tried that. When I choose display all values in same row it show all values in a row, as expected. – arsalan Oct 23 '16 at 6:05
  • But in my case, I want every option in different row populated as select List. So when I unchecked the above option, it shows only the last value in select list. Although in my view, I can see all options, but select list only shows the last one. – arsalan Oct 23 '16 at 6:06
  • @arsalan2411 Have you applied some setting to view's pager?, so that it is taking only last option. I am sure if you fiddle around & do some try and error you will get it right, because if it is showing all values in one case, in otehr case also it should show. There is some settign which interfering. If possible can you paste the screen shot of view's setting page. – CodeNext Oct 23 '16 at 6:11
  • I have added images. Please have a look at those – arsalan Oct 24 '16 at 8:45
  • @arsalan Hey, did you figure out your issue, I tried to guess from your view at that time, but didn't get any idea. I was thinking it might be due to contextual filter(NID), but I think it is not. Hope you would have got the solution by this time. – CodeNext Oct 31 '16 at 16:46

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.