Hardist
Hardist

Reputation: 1993

Bootstrap select2 placeholder in laravel 5.3

I'm using select2 for my laravel project:

https://select2.github.io/examples.html

And I populate my select menus like this:

{{ Form::select('category_id', ['' => ''] + $categories, null, ['id' => 'category_id', 'class' => 'select2']) }}

And my js:

$(".select2").select2({
    placeholder: "Select a category"
});

But this doesn't work, the placeholder doesn't show. Any advice?

Upvotes: 0

Views: 691

Answers (1)

MikeWasawsky
MikeWasawsky

Reputation: 26

Can you include your generated html code?. I think the problem is your selector $(".select2"). The js code inside the select2 function looks ok for me. Try putting the id of the select inside the jQuery function.

So for example if your generated html code is

<select id="my_super_selector">
    <option val="1">1</option>
    ...
</select>

You should use $('#my_super_selector'). Try it and let me know!

Cheers!

Upvotes: 1

Related Questions