PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 1, 2022

[FIXED] How to implement select2 in laravel

 February 01, 2022     html, javascript, jquery-select2, laravel, laravel-5     No comments   

Issue

I have simple input I would like to user select js select2js

Here is my input

<div class="form-group">

    <select class="js-example-basic-multiple form-control" name="states[]" multiple="multiple">
        <option value="AL">Alabama</option>
        ...
        <option value="WY">Wyoming</option>
    </select>

    <!-- Button trigger modal -->

</div>

in my app.blade.php (master) I have this

$(document).ready(function() {
    $('.js-example-basic-multiple').select2()
});

Now when I run my app I get this error

caught TypeError: $(...).select2 is not a function
at HTMLDocument.<anonymous> (create:420)
at j (jquery.min.js:1197)
at k (jquery.min.js:1203)

In console network both js and CSS for select2 are loaded

What is wrong with my code?


Solution

May be due to one of the following reason:

  • Your select2 JS is not added in right place, like you need to add it after jQuery
  • Other JS scripts might have throwing an error which causing all other JS scripts to breaks
  • Your jQuery version is not compatible with the select2 jQuery plugin
  • You may have multiple jQuery added for different jQuery plugin


Answered By - Azhar Rasheed
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing