Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not determine field key for repeater's collapsed value #171

Open
joseph-farruggio opened this issue Mar 29, 2023 · 2 comments
Open

Can not determine field key for repeater's collapsed value #171

joseph-farruggio opened this issue Mar 29, 2023 · 2 comments

Comments

@joseph-farruggio
Copy link

I have a repeater priority_ads and I want the collapsed value to be the ad_title subfield's key. I'm having trouble determining the field's key. The field is added to the repeater using addFields().

I've tried multiple variations of field keys using these docs:
https://github.com/StoutLogic/acf-builder/wiki/generated-keys
https://github.com/StoutLogic/acf-builder/wiki/composing-fields#generated-keys

I get an error each time that the field (based on the key I provided) does not exist.

I've created a simplified version of my implementation:

<?php
use StoutLogic\AcfBuilder\FieldsBuilder;

/**
 * Subfield template
 */
$ad_set = new FieldsBuilder('ad_set');
$ad_set
    ->addTab('ad_content')
    ->addText('ad_title', ['wrapper' => ['width' => '50%']]);

/**
 * Field group with repeater
 */
$wp_custom_ads = new StoutLogic\AcfBuilder\FieldsBuilder('wp_custom_ads');
$wp_custom_ads
    ->addRepeater('priority_ads', ['layout' => 'block', 'button_label' => 'New Ad', 'collapsed' => 'FIELD_KEY_HERE'])
    ->addFields($ad_set)
    ->setLocation('options_page', '==', 'wp-custom-ads');

add_action('acf/init', function () use ($wp_custom_ads) {
    acf_add_local_field_group($wp_custom_ads->build());
});
@stevep
Copy link
Member

stevep commented Mar 29, 2023

Hey @joseph-farruggio I agree the docs probably aren't clear on this, but I tried your example using ad_title as the collapsed key and it worked for me. But maybe in your more complicated example there is another issue?

Screenshot 2023-03-29 at 9 52 10 AM

/**
  * Subfield template
  */
$ad_set = new FieldsBuilder('ad_set');
$ad_set
  ->addTab('ad_content')
  ->addText('ad_title', ['wrapper' => ['width' => '50%']]);

/**
  * Field group with repeater
  */
$wp_custom_ads = new FieldsBuilder('wp_custom_ads');
$wp_custom_ads
  ->addRepeater(
    'priority_ads',
    ['layout' => 'block', 'button_label' => 'New Ad', 'collapsed' => 'ad_title']
  )
  ->addFields($ad_set)
  ->setLocation('options_page', '==', 'wp-custom-ads');

add_action('acf/init', function () use ($wp_custom_ads) {
    acf_add_local_field_group($wp_custom_ads->build());
});

@joseph-farruggio
Copy link
Author

joseph-farruggio commented Mar 29, 2023

That works, thanks!

Based on the docs, I thought it had to be prepended with field_.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants