1

. Hello y'all! I'm trying to have a select input with multiple options on a form. I have several of these but for some reason one is not displaying all of its options. I have tried removing the #'s, changing the order to try to figure out which one specifically is causing the error, and writing the options in a different format, all with no success. If you have any idea why this might be or if I am just unaware of some related syntax restriction please let me know! Thank you so much!

HTML:

{{ Form::select('shelf',
    array(
        '' => 'Shelf',
        '6' => 'SPF 1 x 6 x 6',
        '8' => 'SPF 1 x 2 x 8',
        '8' => 'SPF 1 x 4 x 8',
        '1' => 'WRC 1 x 4 x 8 #1',
        '2' => 'WRC 1 x 4 x 8 #2',
        '1' => 'WRC 1 x 6 x 8 #1',
        '2' => 'WRC 1 x 6 x 8 #2',
        '8' => 'WRC 1 x 2 x 8', 
        '8' => 'WRC 2 x 2 x 8',     
    ), null,
    array('class' => 'shelf', 'id' => null)) 
}}

So far "Shelf" is displayed in the select as the standard option but when clicked the only other options are SPF 1x6x6 , WRC 2x2x8 , WRC 1x6x8 #1 , and WRC 1x6x8 #2 in that order. Any and all help and pointers would be appreciated! Thanks so much!

1 Answer 1

1

You have this:

array(
   ''  => 'Shelf', // --> unique
   '6' => 'SPF 1 x 6 x 6', // --> unique
   '8' => 'SPF 1 x 2 x 8', // --> Not unique/8
   '8' => 'SPF 1 x 4 x 8', // --> Not unique/8
   '1' => 'WRC 1 x 4 x 8 #1', // --> Not unique/1
   '2' => 'WRC 1 x 4 x 8 #2', // --> Not unique/2
   '1' => 'WRC 1 x 6 x 8 #1', // Not unique/1 (This will replace all previous 1)
   '2' => 'WRC 1 x 6 x 8 #2', // --> Not unique/1 (This will replace all previous 2)
   '8' => 'WRC 1 x 2 x 8', --> Not unique/8,
   '8' => 'WRC 2 x 2 x 8', --> Not unique/8, (This will replace all previous 8)
 )

It's because your array contain duplicate keys and the first key is being replaced by the last duplicate key, means that, if you have two '2' then the second '2' will replace the first '2', use unique array keys/option value. Otherwise you will get this:

<select class="shelf" name="shelf">
    <option value="" selected="selected">Shelf</option>
    <option value="6">SPF 1 x 6 x 6</option>
    <option value="8">WRC 2 x 2 x 8</option>
    <option value="1">WRC 1 x 6 x 8 #1</option>
    <option value="2">WRC 1 x 6 x 8 #2</option>
</select>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.