Home › Forums › General Issues › combine radio field with checkbox › Reply To: combine radio field with checkbox
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;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.