FHM09062601IBL - search() merge answer ke options: option terpilih value:true, sesuaikan format object
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -140,6 +140,19 @@ class Screening extends MY_Controller
|
||||
$f['answer'] = $f['answer'] !== null
|
||||
? json_decode($f['answer'], true)
|
||||
: null;
|
||||
|
||||
// Tandai option terpilih dengan value:true agar FE bisa render form pre-filled
|
||||
if ($f['answer'] && $f['M_ScreeningFormOptions'] && $f['M_ScreeningFormAnswerType'] !== 'text') {
|
||||
if ($f['M_ScreeningFormAnswerType'] === 'single') {
|
||||
$selected = [$f['answer']['id'] ?? ''];
|
||||
} else {
|
||||
$selected = array_column((array)$f['answer'], 'id');
|
||||
}
|
||||
foreach ($f['M_ScreeningFormOptions'] as &$opt) {
|
||||
$opt['value'] = in_array($opt['id'], $selected);
|
||||
}
|
||||
unset($opt);
|
||||
}
|
||||
}
|
||||
unset($f);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user