forked from fa/breadcrumb-the-shire
fix(helpdesk): user-select as multi-select, store as JSON array
- select multiple, no placeholder option (was causing two empty entries) - value stored as JSON array string e.g. ["1","3"] - on render decode JSON back to array for selected check - both create and edit actions read field as array Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -58,6 +58,13 @@ $hasDiff = $fieldDiff !== [];
|
||||
</div>
|
||||
|
||||
<?php elseif ($type === 'user-select'): ?>
|
||||
<?php
|
||||
$selectedIds = [];
|
||||
if ($value !== '') {
|
||||
$decoded = json_decode($value, true);
|
||||
$selectedIds = is_array($decoded) ? array_map('strval', $decoded) : [$value];
|
||||
}
|
||||
?>
|
||||
<div class="handover-diff-field<?php e($diffClass); ?>">
|
||||
<label for="<?php e($inputId); ?>">
|
||||
<?php e($label); ?>
|
||||
@@ -65,18 +72,19 @@ $hasDiff = $fieldDiff !== [];
|
||||
</label>
|
||||
<select
|
||||
id="<?php e($inputId); ?>"
|
||||
name="field_<?php e($key); ?>"
|
||||
name="field_<?php e($key); ?>[]"
|
||||
multiple
|
||||
size="5"
|
||||
<?php if ($required): ?> aria-required="true"<?php endif; ?>
|
||||
<?php if ($readonly): ?> disabled<?php endif; ?>
|
||||
>
|
||||
<option value=""><?php e(t('Please select...')); ?></option>
|
||||
<?php foreach ($tenantUsers as $u):
|
||||
$uId = (string) ($u['id'] ?? '');
|
||||
$uName = trim((string) ($u['display_name'] ?? ''));
|
||||
$uEmail = (string) ($u['email'] ?? '');
|
||||
$uLabel = $uName !== '' ? $uName : $uEmail;
|
||||
?>
|
||||
<option value="<?php e($uId); ?>"<?php if ($value === $uId): ?> selected<?php endif; ?>>
|
||||
<option value="<?php e($uId); ?>"<?php if (in_array($uId, $selectedIds, true)): ?> selected<?php endif; ?>>
|
||||
<?php e($uLabel); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@@ -261,6 +261,9 @@ if ($step === $protocolStep) {
|
||||
$type = $field['type'] ?? 'text';
|
||||
if ($type === 'checkbox') {
|
||||
$fieldValues[$key] = $request->body('field_' . $key, '') !== '' ? '1' : '0';
|
||||
} elseif ($type === 'user-select') {
|
||||
$ids = $request->body('field_' . $key, []);
|
||||
$fieldValues[$key] = json_encode(array_values(array_filter((array) $ids)));
|
||||
} else {
|
||||
$fieldValues[$key] = (string) $request->body('field_' . $key, '');
|
||||
}
|
||||
|
||||
@@ -148,6 +148,9 @@ if ($request->isMethod('POST') && $canEdit) {
|
||||
$type = $field['type'] ?? 'text';
|
||||
if ($type === 'checkbox') {
|
||||
$submittedValues[$key] = $request->body('field_' . $key, '') !== '' ? '1' : '0';
|
||||
} elseif ($type === 'user-select') {
|
||||
$ids = $request->body('field_' . $key, []);
|
||||
$submittedValues[$key] = json_encode(array_values(array_filter((array) $ids)));
|
||||
} else {
|
||||
$submittedValues[$key] = (string) $request->body('field_' . $key, '');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user