Skip to content

Commit 33c9ea4

Browse files
authored
Merge pull request #16065 from marcusmoore/chore/migrate-select-helper
Convert Form::select to blade component
2 parents 8c164d1 + d88fe1f commit 33c9ea4

29 files changed

+299
-124
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@props([
2+
// <options> can either be provided as key => value pairs
3+
// or passed in via the default $slot
4+
'options',
5+
'selected' => null,
6+
'includeEmpty' => false,
7+
'forLivewire' => false,
8+
])
9+
10+
<select
11+
{{ $attributes->class(['select2', 'livewire-select2' => $forLivewire]) }}
12+
@if($forLivewire) data-livewire-component="{{ $this->getId() }}" @endif
13+
>
14+
@if($includeEmpty)
15+
<option value=""></option>
16+
@endif
17+
{{-- map the simple key => value pairs when nothing is passed in via the slot --}}
18+
@if($slot->isEmpty())
19+
@foreach($options as $key => $value)
20+
<option value="{{ $key }}" @selected($selected == $key)>{{ $value }}</option>
21+
@endforeach
22+
@else
23+
{{ $slot }}
24+
@endif
25+
</select>

resources/views/categories/edit.blade.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
<div class="form-group {{ $errors->has('category_type') ? ' has-error' : '' }}">
1616
<label for="category_type" class="col-md-3 control-label">{{ trans('general.type') }}</label>
1717
<div class="col-md-7 required">
18-
{{ Form::select('category_type', $category_types , old('category_type', $item->category_type), array('class'=>'select2', 'style'=>'min-width:350px', 'aria-label'=>'category_type', ($item->category_type!='') || ($item->itemCount() > 0) ? 'disabled' : '')) }}
18+
<x-input.select
19+
name="category_type"
20+
:options="$category_types"
21+
:selected="old('category_type', $item->category_type)"
22+
:disabled="$item->category_type!='' || $item->itemCount() > 0"
23+
style="min-width:350px"
24+
aria-label="category_type"
25+
/>
1926
{!! $errors->first('category_type', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
2027
</div>
2128
<div class="col-md-7 col-md-offset-3">

resources/views/custom_fields/fields/edit.blade.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,14 @@
9494
}
9595
@endphp
9696
<div class="col-md-8 required">
97-
{{ Form::select("format",Helper::predefined_formats(), ($field_format == '') ? $field->format : $field_format, array('class'=>'format select2 form-control', 'aria-label'=>'format', 'style' => 'width:100%;')) }}
97+
<x-input.select
98+
name="format"
99+
:options="Helper::predefined_formats()"
100+
:selected="($field_format == '') ? $field->format : $field_format"
101+
class="format form-control"
102+
style="width:100%"
103+
aria-label="format"
104+
/>
98105
{!! $errors->first('format', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
99106
</div>
100107
</div>

resources/views/custom_fields/fieldsets/view.blade.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@
9595
<label for="field_id" class="sr-only">
9696
{{ trans('admin/custom-field/general.add_field_to_fieldset')}}
9797
</label>
98-
{{ Form::select("field_id",$custom_fields_list,"",['aria-label'=>'field_id', 'class'=>'select2', 'style' => 'min-width:400px;']) }}
99-
98+
<x-input.select
99+
name="field_id"
100+
:options="$custom_fields_list"
101+
style="min-width:400px"
102+
aria-label="field_id"
103+
/>
100104
</div>
101105

102106
<div class="form-group" style="display: none;">

resources/views/hardware/bulk.blade.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,13 @@
125125
{{ trans('admin/hardware/form.status') }}
126126
</label>
127127
<div class="col-md-7">
128-
{{ Form::select('status_id', $statuslabel_list , old('status_id'), array('class'=>'select2', 'style'=>'width:100%', 'aria-label'=>'status_id')) }}
128+
<x-input.select
129+
name="status_id"
130+
:options="$statuslabel_list"
131+
:selected="old('status_id')"
132+
style="width: 100%"
133+
aria-label="status_id"
134+
/>
129135
<p class="help-block">{{ trans('general.status_compatibility') }}</p>
130136
{!! $errors->first('status_id', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
131137
</div>

resources/views/hardware/checkin.blade.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@
8484
{{ trans('admin/hardware/form.status') }}
8585
</label>
8686
<div class="col-md-8 required">
87-
{{ Form::select('status_id', $statusLabel_list, '', array('class'=>'select2', 'style'=>'width:100%','id' =>'modal-statuslabel_types', 'aria-label'=>'status_id')) }}
87+
<x-input.select
88+
name="status_id"
89+
id="modal-statuslabel_types"
90+
:options="$statusLabel_list"
91+
style="width: 100%"
92+
aria-label="status_id"
93+
/>
8894
{!! $errors->first('status_id', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
8995
</div>
9096
</div>
@@ -154,4 +160,4 @@
154160
</div>
155161
</div>
156162

157-
@stop
163+
@stop

resources/views/hardware/checkout.blade.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,13 @@
8282
{{ trans('admin/hardware/form.status') }}
8383
</label>
8484
<div class="col-md-7 required">
85-
{{ Form::select('status_id', $statusLabel_list, $asset->status_id, array('class'=>'select2', 'style'=>'width:100%','', 'aria-label'=>'status_id')) }}
85+
<x-input.select
86+
name="status_id"
87+
:options="$statusLabel_list"
88+
:selected="$asset->status_id"
89+
style="width: 100%;"
90+
aria-label="status_id"
91+
/>
8692
{!! $errors->first('status_id', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
8793
</div>
8894
</div>

resources/views/hardware/quickscan-checkin.blade.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@
4747
{{ trans('admin/hardware/form.status') }}
4848
</label>
4949
<div class="col-md-7">
50-
{{ Form::select('status_id', $statusLabel_list, '', array('class'=>'select2', 'style'=>'width:100%','', 'aria-label'=>'status_id')) }}
50+
<x-input.select
51+
name="status_id"
52+
id="status_id"
53+
:options="$statusLabel_list"
54+
style="width:100%"
55+
aria-label="status_id"
56+
/>
5157
{!! $errors->first('status_id', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
5258
</div>
5359
</div>

resources/views/livewire/custom-field-set-default-values-for-model.blade.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44
{{ trans('admin/models/general.fieldset') }}
55
</label>
66
<div class="col-md-5">
7-
{{ Form::select('fieldset_id', Helper::customFieldsetList(), old('fieldset_id', $fieldset_id), array('class'=>'select2 js-fieldset-field livewire-select2', 'style'=>'width:100%; min-width:350px', 'aria-label'=>'custom_fieldset', 'data-livewire-component' => $this->getId())) }}
7+
<x-input.select
8+
name="fieldset_id"
9+
id="fieldset_id"
10+
:options="Helper::customFieldsetList()"
11+
:selected="old('fieldset_id', $fieldset_id)"
12+
:for-livewire="true"
13+
class="js-fieldset-field"
14+
style="width:100%; min-width:350px;"
15+
aria-label="custom_fieldset"
16+
/>
817
{!! $errors->first('custom_fieldset', '<span class="alert-msg" aria-hidden="true"><br><i class="fas fa-times"></i> :message</span>') !!}
918
</div>
1019
<div class="col-md-3">

resources/views/livewire/importer.blade.php

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,20 @@ class="col-md-12 table table-striped snipe-table">
155155
</label>
156156

157157
<div class="col-md-9 col-xs-12">
158-
{{ Form::select('typeOfImport', $importTypes, $typeOfImport, [
159-
'id' => 'import_type',
160-
'class' => 'livewire-select2',
161-
'style' => 'min-width: 350px',
162-
'data-placeholder' => trans('general.select_var', ['thing' => trans('general.import_type')]),
163-
'placeholder' => '', //needed so that the form-helper will put an empty option first
164-
'data-minimum-results-for-search' => '-1', // Remove this if the list gets long enough that we need to search
165-
'data-livewire-component' => $this->getId()
166-
]) }}
158+
<x-input.select
159+
name="typeOfImport"
160+
id="import_type"
161+
:options="$importTypes"
162+
:selected="$typeOfImport"
163+
:for-livewire="true"
164+
:include-empty="true"
165+
:data-placeholder="trans('general.select_var', ['thing' => trans('general.import_type')])"
166+
{{--placeholder needed so that the form-helper will put an empty option first--}}
167+
placeholder=""
168+
{{--Remove this if the list gets long enough that we need to search--}}
169+
data-minimum-results-for-search="-1"
170+
style="min-width: 350px;"
171+
/>
167172
@if ($typeOfImport === 'asset' && $snipeSettings->auto_increment_assets == 0)
168173
<p class="help-block">
169174
{{ trans('general.auto_incrementing_asset_tags_disabled_so_tags_required') }}
@@ -238,17 +243,22 @@ class="col-md-12 table table-striped snipe-table">
238243

239244
<label for="field_map.{{ $index }}" class="col-md-3 control-label text-right">{{ $header }}</label>
240245
<div class="col-md-4">
241-
242-
{{ Form::select('field_map.'.$index, $columnOptions[$typeOfImport], @$field_map[$index],
243-
[
244-
'class' => 'mappings livewire-select2',
245-
'placeholder' => trans('general.importer.do_not_import'),
246-
'style' => 'min-width: 100%',
247-
'data-livewire-component' => $this->getId()
248-
],[
249-
'-' => ['disabled' => true] // this makes the "-----" line unclickable
250-
])
251-
}}
246+
<x-input.select
247+
:name="'field_map.'.$index"
248+
:for-livewire="true"
249+
:placeholder="trans('general.importer.do_not_import')"
250+
class="mappings"
251+
style="min-width: 100%;"
252+
>
253+
<option selected="selected" value="">Do Not Import</option>
254+
@foreach($columnOptions[$typeOfImport] as $key => $value)
255+
<option
256+
value="{{ $key }}"
257+
@selected(@$field_map[$index] === $key)
258+
@disabled($key === '-')
259+
>{{ $value }}</option>
260+
@endforeach
261+
</x-input.select>
252262
</div>
253263
@if (($this->activeFile->first_row) && (array_key_exists($index, $this->activeFile->first_row)))
254264
<div class="col-md-5">

0 commit comments

Comments
 (0)