0
votes

I populated my Select option using laravel collective htmlServiceProvider

<div class="col-md-6">
     {!! Form::label('Serial'  ,null,['class'=>'small']) !!}
     {!! Form::select('cross_match_id',$serials,null,['class'=>'select2 input-sm form-control','id'=>'cross_match_id']) !!}
</div>

I set my the default value from the database using Jquery

$('#cross_match_id').val(data.cross_match_id);

If I don't use select2 the default value and value's text will be set. But when I use Select2 its just empty. Although I can see that it has default value but not set.

How to to set default value and text with select2

2
Why not select the default value with PHP? Is there some user interaction before the default should be selected? - Thomas Van der Veen

2 Answers

2
votes

You have to use change trigger for update in select2 after set value

$('#cross_match_id').val(data.cross_match_id).change();
0
votes

Try this:

// to select the first blank value
("#id").select2().select2("val", null);

// to select specific value
$("#id").select2().select2("val", 'oneofthevaluehere');