Home › Forums › Backend Issues (wp-admin) › Are conditional field settings possible? › Reply To: Are conditional field settings possible?
Fix for my “Update” issue above:
In the issue above, Field 3 conditional settings weren’t working appropriately. The fields that were supposed to be hidden where indeed hidden, but the toggle to reveal them no longer revealed them.
After many hours digging deep into ACF’s javascript and much trial and error, I finally found that calling acf.getField($field)
is what is instantiating those fields properly. Why it isn’t working properly in my example, I’m not sure, but here’s the fix:
/**
* Fires when duplicating a field from a previously unsaved, duplicated field.
*/
// Only targeting select fields for this example
acf.add_action('append_field/type=select', function ($field) {
// Only target select fields that have my custom class
if ($field.hasClass('my-custom-class')) {
// Instantiate hidden sibling fields so conditionals and Select2 UI work
acf.getFields($field.siblings('.my-custom-class.acf-hidden'))
}
})
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.