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

Saturday, February 19, 2022

[FIXED] select2 js empty value on load in select option

 February 19, 2022     jquery-select2, laravel-5     No comments   

Issue

I have implemented select2js in my project, In few cases when i load my page, an empty value is appending to my select input box. Can anyone help me out, what is the issue, I have added a image of it and My code is

{!! Form::select('searchSkillTools[]',[],(isset($skillToolXref) && $skillToolXref!='')?$skillToolXref:'', array('autocomplete' => 'off', 'class' => 'chosen-select','multiple'=>'multiple', 'id' => 'searchSkillTools-'.$randomId, 'placeholder' => '' ,'style' => 'height: auto !important')) !!}

$('#searchSkillTools-{{$randomId}}').select2({  
    ajax: {
        url: skillToolUrl,
        dataType: 'json',
        method:'get',
        delay: 250,//delay in response
        data: function (data) {
            return {
                search: data.term //search term
            };
        },
        /*option to transform the data returned by response into the format expected by Select2*/
        processResults: function (response) {            
            return {
                results:response
            };
        },
        cache: true
    }
});

enter image description here


Solution

This way will fix the bug:

(isset($skillToolXref) && $skillToolXref!='')?$skillToolXref:null



Answered By - Andy
  • 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