3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-02-20 14:45:31 +00:00

checkboxes properly check

This commit is contained in:
Godfrey M
2025-07-17 11:56:52 -07:00
parent c8b213c190
commit 5df22b3e6a
3 changed files with 23 additions and 10 deletions

View File

@ -128,7 +128,8 @@ class Handler extends ExceptionHandler
$ids = method_exists($e, 'getIds') ? $e->getIds() : [];
if (in_array('bulkedit', $ids, true)) {
$oldInput = session()->getOldInput();
session()->flashInput($oldInput ?? []);
return redirect()
->route('hardware.bulkedit')
->with('bulk_asset_errors', session()->pull('bulk_asset_errors'))

View File

@ -125,6 +125,7 @@ class BulkAssetsController extends Controller
$models = $assets->unique('model_id');
$modelNames = [];
foreach($models as $model) {
$modelNames[] = $model->model->name;
}
@ -160,7 +161,6 @@ class BulkAssetsController extends Controller
case 'edit':
$this->authorize('update', Asset::class);
return view('hardware/bulk')
->with('assets', $asset_ids)
->with('statuslabel_list', Helper::statusLabelList())
@ -767,5 +767,4 @@ class BulkAssetsController extends Controller
->with('models', $models->pluck(['model']))
->with('modelNames', $modelNames);
}
}

View File

@ -55,14 +55,27 @@
@if(!$field->is_unique)
<textarea class="col-md-6 form-control" id="{{ $field->db_column_name() }}" name="{{ $field->db_column_name() }}">{{ old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, $item->{$field->db_column_name()}) : $field->defaultValue($model->id))) }}</textarea>
@endif
@elseif ($field->element=='checkbox')
@elseif ($field->element=='checkbox')<pre>{{ var_dump(old()) }}</pre>
<!-- Checkboxes -->
@foreach ($field->formatFieldValuesAsArray() as $key => $value)
<label class="form-control">
<input type="checkbox" value="{{ $value }}" name="{{ $field->db_column_name() }}[]" {{ isset($item) ? (in_array($value, array_map('trim', explode(',', $item->{$field->db_column_name()}))) ? ' checked="checked"' : '') : (old($field->db_column_name()) != '' ? ' checked="checked"' : (in_array($key, array_map('trim', explode(',', $field->defaultValue($model->id)))) ? ' checked="checked"' : '')) }}>
{{ $value }}
</label>
@endforeach
@php
$fieldName = $field->db_column_name();
$oldValues = old($fieldName);
$defaultValues = array_map('trim', explode(',', $field->defaultValue($model->id)));
$currentValues = isset($item) ? array_map('trim', explode(',', $item->{$fieldName})) : $defaultValues;
// if old values exist, use them, otherwise fallback
$selectedValues = is_array($oldValues) ? $oldValues : $currentValues;
@endphp
@foreach ($field->formatFieldValuesAsArray() as $key => $value)
<label class="form-control">
<input type="checkbox"
name="{{ $fieldName }}[]"
value="{{ $key }}"
{{ in_array($key, $selectedValues) ? 'checked' : '' }}>
{{ $value }}
</label>
@endforeach
@elseif ($field->element=='radio')
@foreach ($field->formatFieldValuesAsArray() as $value)