lundi 18 juillet 2016

Populating select options dynamically based on previous choices

I am having issues prepopulating select boxes based on an array. Now I am passing my view an array which looks like the following

array:4 [▼
  "folder1" => array:1 [▶]
  "folder2" => array:2 [▶]
  "folder3" => array:1 [▶]
  "folder4" => array:1 [▼
    "product1" => array:1 [▼
      2016 => array:1 [▼
        "March" => array:1 [▼
          0 => "image1.png"
        ]
      ]
    ]
    "product2" => array:1 [▼
      2015 => array:1 [▼
        "June" => array:1 [▼
          0 => "image1.png"
        ]
      ]
    ]
  ]
]

Now for this part I am only interested in folder4. I plan on having 4 select inputs. The first one should display the products. The products are folders within the root of folder4.

So in the example above, this select should show product1 and product2.

The second select should show the years. The years are folders within the products. The third select should show the months. The months are folders within the years folders.

The last select should show the image names.

All of this will probably need to be within the foreach loop. Reason I say this is because if they select product2 in the first select box, the next select box should only have the year 2015, not the year from product1 folder. This is where I am at this moment in time, but it is quite a way off

<select class="selectpicker" name="productType">
    @foreach($fileData as $type => $product)
        @if($type == "folder4")
            @foreach($product as $name => $year)
                <option value=""></option>
            @endforeach
        @endif
    @endforeach
</select>

At the moment I am getting htmlentities() expects parameter 1 to be string, array given. This select should display product1 and product2. Also, have do I make the other select options dynamic based on what has been previously chosen? So if they choose product 1, the next select box should display the year 2016 only.

Any advice appreciated.

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire