简体   繁体   English

选项标签未使用选择2在laravel 5.1中显示默认选择的选项

[英]Option tag not displaying default selected choice in laravel 5.1 using select2

I have been facing a strange problem in select2.The default selected option I want to display is not happening.If the cursor is placed on the select2 box in question,it displays the required value as an 'alt' attribute in image.So the thing is that the value is passed to the select2 box but it isnt displayed!Here's my code: 我在select2中遇到了一个奇怪的问题。我要显示的默认选定选项没有发生。如果将光标放在有问题的select2框中,它将所需的值显示为图像中的“ alt”属性。问题是该值已传递到select2框,但未显示!这是我的代码:

<div class="row">
<?php
$country = explode('_', $patron_address['country']);
$countryId = $country[0];
$countryCode = $country[1];
$countryName = $country[2];
?>
   <div class='col-md-6'>
      <div class="form-group{!! ($errors->has('country'))? ' has-error':'' !!}">
         <label for="country" class="control-label col-md-3"> Country <span class="required" aria-required="true">*</span> </label>
         <div class="col-md-8">
            <select name="country" id="select2_country" class="form-control">
               <option></option>
               @if($country)
               <option value="{!! $countryName !!}" selected="selected">{!! $countryName !!}</option>
               @endIf
            </select>
            @if ($errors->has('country')) <span class="help-block">{!! $errors->first('country') !!}</span> @endif </div>
      </div>
      `enter code here` </div>
</div>

Even if instead of {!! 即使不是{!! $countryName !!},if I use any hard coded option to be displayed,same problem persists. $ countryName !!},如果我使用任何硬编码选项来显示,同样的问题仍然存在。 It's been done in laravel 5.1. 它已在laravel 5.1中完成。 Any suggestions? 有什么建议么?

can you please check the value of $patron_address['country'],because i found the following code works fine 能否请您检查$ patron_address ['country']的值,因为我发现以下代码可以正常工作

<div class="row">
<?php
$country = explode('_', 'test1_test2_test3');
$countryId = $country[0];
$countryCode = $country[1];
$countryName = $country[2];
?>
   <div class='col-md-6'>
      <div class="form-group{!! ($errors->has('country'))? ' has-error':'' !!}">
         <label for="country" class="control-label col-md-3"> Country <span class="required" aria-required="true">*</span> </label>
         <div class="col-md-8">
            <select name="country" id="select2_country" class="form-control">
               <option></option>
               @if($country)
               <option value="{!! $countryName !!}" selected="selected">{!! $countryName !!}</option>
               @endIf
            </select>
            @if ($errors->has('country')) <span class="help-block">{!! $errors->first('country') !!}</span> @endif </div>
      </div>
      `enter code here` </div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM