Hello,
I would like to add a radio field followed by a checkbox.
I want this feature in order to mark the correct answer.
Willing to listen to any other proposals.
Thank you,
George
I know this is an extremely old topic and I’m assuming that you’ve either found a solution or moved on. I just thought I’d post my thoughts for others that happen on this topic looking for a similar solution.
I would create a true/false field following each question and I would create an acf/load_field filter that would set the readonly and disabled attibutes of the fields depending on the status of the user.
All of the code is not here, this is just a rough outline.
add_filter('acf/load_field/type=true_false', 'acf_disable_readonly');
function acf_disable_readonly($field) {
$key = $field['key'];
$name = $field['name'];
// check wither the key or name against
// a list of fields that you want to change
if (!$one_of_your_fieldd) {
return $field;
}
// then get the current user information
// and test this against who should be able
// to modify it
if (!$allowed_to_modify) {
$field['readonly'] = 1;
$field['disabled'] = 1;
// as a bonus, hide the field using
// conditional logic that can never be true
$field['conditional_logic'] = array(
array(
// add two possible values that can never happen at the same time
array(
'field' => 'field_doesnotexist',
// or any field key
// i'm not sure what will happen
// if the field does not exist
'operator' => '==',
'value' => 0
),
array(
'field' => 'field_doesnotexist',
// or any field key
// i'm not sure what will happen
// if the field does not exist
'operator' => '==',
'value' => 1
)
)
); // end conditional logic
}
return $field;
}