【问题标题】:How can I select all the options in a multi select form laravel?如何在多选表单 laravel 中选择所有选项?
【发布时间】:2021-07-25 14:49:37
【问题描述】:

数据正在从数据库中获取,我想默认选择来自数据库的所有位置

 @php
          $default_location = null;
          if(count($business_locations) == 1){
            $default_location = array_key_first($business_locations->toArray());
          }
        @endphp
        <div class="col-sm-4">
          <div class="form-group">
            {!! Form::label('product_locations', __('business.business_locations') . ':') !!} @show_tooltip(__('lang_v1.product_location_help'))
              {!! Form::select('product_locations[]', $business_locations, $default_location, ['class' => 'form-control select2', 'multiple', 'id' => 'product_locations']); !!}
          </div>
        </div>

【问题讨论】:

  • {!! Form::select('product_locations[]', $business_locations, $default_location, ['class' =&gt; 'form-control select2', 'multiple', 'id' =&gt; 'product_locations'], 'selected' =&gt; 'true'); !!} 我认为它可以满足您的需求。

标签: mysql laravel


【解决方案1】:

您可以使用 jquery 选择所有。

$(document).ready(function(){
// all selected
$("#product_locations").prop('checked', true);
});

【讨论】:

猜你喜欢
  • 2012-04-13
  • 2015-08-07
  • 1970-01-01
  • 2016-06-19
  • 2017-11-27
  • 1970-01-01
  • 1970-01-01
  • 2017-10-15
  • 1970-01-01
相关资源
最近更新 更多