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>
|
</div>
|
||||||
|
|
||||||
<?php elseif ($type === 'user-select'): ?>
|
<?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); ?>">
|
<div class="handover-diff-field<?php e($diffClass); ?>">
|
||||||
<label for="<?php e($inputId); ?>">
|
<label for="<?php e($inputId); ?>">
|
||||||
<?php e($label); ?>
|
<?php e($label); ?>
|
||||||
@@ -65,18 +72,19 @@ $hasDiff = $fieldDiff !== [];
|
|||||||
</label>
|
</label>
|
||||||
<select
|
<select
|
||||||
id="<?php e($inputId); ?>"
|
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 ($required): ?> aria-required="true"<?php endif; ?>
|
||||||
<?php if ($readonly): ?> disabled<?php endif; ?>
|
<?php if ($readonly): ?> disabled<?php endif; ?>
|
||||||
>
|
>
|
||||||
<option value=""><?php e(t('Please select...')); ?></option>
|
|
||||||
<?php foreach ($tenantUsers as $u):
|
<?php foreach ($tenantUsers as $u):
|
||||||
$uId = (string) ($u['id'] ?? '');
|
$uId = (string) ($u['id'] ?? '');
|
||||||
$uName = trim((string) ($u['display_name'] ?? ''));
|
$uName = trim((string) ($u['display_name'] ?? ''));
|
||||||
$uEmail = (string) ($u['email'] ?? '');
|
$uEmail = (string) ($u['email'] ?? '');
|
||||||
$uLabel = $uName !== '' ? $uName : $uEmail;
|
$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); ?>
|
<?php e($uLabel); ?>
|
||||||
</option>
|
</option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|||||||
@@ -261,6 +261,9 @@ if ($step === $protocolStep) {
|
|||||||
$type = $field['type'] ?? 'text';
|
$type = $field['type'] ?? 'text';
|
||||||
if ($type === 'checkbox') {
|
if ($type === 'checkbox') {
|
||||||
$fieldValues[$key] = $request->body('field_' . $key, '') !== '' ? '1' : '0';
|
$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 {
|
} else {
|
||||||
$fieldValues[$key] = (string) $request->body('field_' . $key, '');
|
$fieldValues[$key] = (string) $request->body('field_' . $key, '');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,6 +148,9 @@ if ($request->isMethod('POST') && $canEdit) {
|
|||||||
$type = $field['type'] ?? 'text';
|
$type = $field['type'] ?? 'text';
|
||||||
if ($type === 'checkbox') {
|
if ($type === 'checkbox') {
|
||||||
$submittedValues[$key] = $request->body('field_' . $key, '') !== '' ? '1' : '0';
|
$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 {
|
} else {
|
||||||
$submittedValues[$key] = (string) $request->body('field_' . $key, '');
|
$submittedValues[$key] = (string) $request->body('field_' . $key, '');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user