StoutLogic / acf-builder

An Advanced Custom Field Configuration Builder
GNU General Public License v2.0
792 stars 61 forks source link

Add empty conditional info to docs #158

Closed Harry-Gardiner closed 2 years ago

Harry-Gardiner commented 2 years ago

On the conditional page it states that "ACF allows fields to be visible or hidden based on the values of other fields, but only based on a field that has choices: checkbox, radio, select, true_false.", but visibility of fields can also be controlled by checking to see if a field is empty.

->addText( 'title', [ 'label' => 'Title', ] )

->addRadio('title_width', [ 'label' => 'Choose title width', 'choices' => [ 'wide' => 'Wide', 'narrow' => 'Narrow' ], ]) ->conditional('title', '!=', '')

If the title field is empty the radio title_width is hidden. If the input is populated the radio fields show.

Worth adding this empty logic to the docs?

stevep commented 2 years ago

Great idea! Had to test this myself because I didn't know it was possible. Not even the official ACF docs mention it, and say it is limited it to the field types originally listed. https://www.advancedcustomfields.com/resources/field-settings/

This is updated in the ACF Builder docs with an example. https://github.com/StoutLogic/acf-builder/wiki/Conditions