I am wanting to make a new field type for image selections (a radio select field, but with images).
How can I start. Should I make it based off of the default select field in order to be able to have it usable with conditional logic?
I have tried to create from the custom field template, but I cannot get conditional logic to work. Any Ideas?
I’m not sure why you need to build a new field type. I would do something like this.
And I am familiar with that post. But I want to use conditional logic.
I would think that this should be a main feature with the radio field.
Conditional logic in ACF is not a function of a specific field that conditions are based on. Conditional logic is a function of the fields that are conditional. There isn’t anything in the radio field that says “I can be used for conditional logic”
SO acf-input.js starting at Line 9700 is where the Conditional Logic is happening..
There is also where certain fields are allowed.
If we can simply hook into the js functions and add our custom field to the array I guessing this should work in custom fields.
About the radio/checkbox fields. I think there should be a setting that allow users to assign a image instead of a check or a dot.
red : Red : /images/red.png
yellow : Yellow : /images/yellow.png
If you want this built into the current field then I’d suggest contacting the developer. https://www.advancedcustomfields.com/contact/. The more requests the developer gets the more likely he is to think about adding a feature.
I am a developer, when I need something like this I generally work with what’s already in ACF and use filters and add customization for specific fields.
You can already do basically what you are asking by specifying images for labels and then just add some customization using css/js
red : <img src="url-of-red.jpg"> yellow : <img src="url-of-yellow.jpg">
It may be possible to
.extend the other fields to modify the conditional logic. I think I’ve tried this in the past. I don’t remember who it turned out and I can’t find it in my archives.
If I needed to do this a lot I might consider adding a custom field setting to the existing field type https://www.advancedcustomfields.com/resources/adding-custom-settings-fields/ and then use an acf/render_field filter to modify the choices displayed and then add custom CSS and JS as needed by using a specific class for the field wrapper. I might even go as far as making my new field setting dynamic based on the values entered into the ACF choices field using custom JS. Nearly any field type built in to ACF can be used as a field setting in any other field type. As an example if you take a look at my medium editor plugin, this field type that I build uses a repeater field as one of its field settings. It is even possible to use an image field as a field setting https://support.advancedcustomfields.com/forums/topic/default-value-for-images/. Taking it a little further you could have a radio field as a field setting that toggles between standard input and image input and then dynamically populate the built in ACF choice field base on whatever is entered into the custom field settings for images.
Sorry, I may have gone off in many directions, just trying to help give you options on how to get to where you want to go without building a new field that would require hacking the ACF files.
You must be logged in to reply to this topic.
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!
© 2020 Advanced Custom Fields. Subscribe