I have found the need to change a label of a field conditionally. Lately I have just been trying to come up with a label that closely matches, but it would be nice not to have to.
I need all other attributes of that field to stay the same.
I am thinking something like this:
'key' => 'field_type_label', 'label' => array ( array ( array ( 'field' => 'field_type', 'operator' => '==', 'value' => 'video', 'label' => 'Video Text' ), ), array ( array ( 'field' => 'field_type', 'operator' => '==', 'value' => 'image', 'label' => 'Image Caption' ), ), ), 'name' => 'text', 'type' => 'text',
The above is just an example.
So lets say I have 2 fields:
– format (radio buttons with two options [‘image’, ‘video’])
– content (textarea)
When the user (In the Admin) chooses format to be ‘image’ I would like the label for ‘content’ to be ‘Caption’.
When the user chooses format to be ‘video’ I would like the label for ‘content’ to be ‘Description’.
Sure, I could create two fields ‘caption’ and ‘description’ and set them conditionally based on ‘format’. The issue is then the user will have to copy their text and paste it in the next field. Which may not sound like a big deal, but when dealing with a repeater field where they have 20+ entries then it becomes one. Also I don’t want to have to add additional conditionals in my PHP code to retrieve the content.
I can understand that this may be an issue when trying to figure out the best way to do this in the GUI, but my team and I don’t use the GUI. We build out all the fields using PHP. So for now I am just hoping that this can be done with PHP.
This isn’t something that can be done using PHP. When a repeater field is generated there is a ‘clone’ version of the row that is hidden. When you add a row ACF copies that hidden row to make the new row.
There is nothing in ACF that will let you conditionally change the label of a field, or any other aspect of a field, based on another field. I’m not the developer, but I honestly don’t see features like this making it into ACF.
Yes, this is just a feature request. I understand that JS is required to do this, but I am just asking that a dev can use PHP or JSON to build this functionality in just like we can do with ‘conditional_logic’. It would make my teams and I job much easier.
I would still like this reviewed and considered.
To get this feature request to the developer submit a support ticket https://support.advancedcustomfields.com/new-ticket/ …. yes, the forum title says feature requests, but E does not get here much. He depends on other users so that he can spend his time working on ACF. As far as I know any feature requests sent in as a ticket are added to a list so they are easier to manage, although, I can’t be sure because I am not part of that system.
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!
Sorry for the issues with ACF's API SSL certificate this morning. We've resolved it and your activations and downloads should be back to normal again. Thanks! ^LG— Advanced Custom Fields (@wp_acf) November 2, 2022
© 2022 Advanced Custom Fields.