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

JS acf.findFields returns unrequested types in ACF6 #765

Open
herrvigg opened this issue Nov 19, 2022 · 1 comment
Open

JS acf.findFields returns unrequested types in ACF6 #765

herrvigg opened this issue Nov 19, 2022 · 1 comment

Comments

@herrvigg
Copy link

herrvigg commented Nov 19, 2022

The new Javascript API doesn't behave as expected with ACF6 (up to 6.0.5).

acf.findFields({type: 'text'})

When editing a field group, this returns other elements with data-type="tab" like this:

<div class="acf-field acf-field-tab acf-field-acf-field-group-settings-tabs"
     data-type="tab" data-key="acf_field_group_settings_tabs">

Expected result: only elements of data-type="text", not tab.

Looking at the value of the internal selector in findFields there have been some changes but we can see there's still a regression:

ACF 5.12.4 - OK
.acf-field[data-type="text"]:visible
ACF 6.0.3 - WRONG
.acf-field[data-type="text"]:visible,, .acf-field-acf-field-settings-tabs, .acf-field-acf-field-group-settings-tabs
ACF 6.0.5 - WRONG
.acf-field[data-type="text"]:visible,, .acf-field-acf-field-group-settings-tabs

By debugging the JS scripts I found the tabs are added by this find_fields_selector filter:

if (!args.suppressFilters) {
selector = acf.applyFilters('find_fields_selector', selector, args);
}

--> adds '.acf-field-acf-field-group-settings-tabs'

Why and where does it come from? I didn't set this filter, so it should not be a result of the user request.
It can be disabled by suppressFilters as a workaround but this field is not even documented. IMO it should not be set by the user to filter unexpected results. The default behavior should remain as in ACF5.

@herrvigg herrvigg changed the title getFields returns unrequested types in ACF6 JS acf.findFields returns unrequested types in ACF6 Nov 19, 2022
@mattgrshaw
Copy link
Member

@herrvigg Thanks for the report.

This was done in order to add support for the tabs in the new UI that was introduced in 6.0, and these fields should only show up if acf.findFields() is called while in the field group editor.

However, I can see how this definitely isn't ideal (especially when checking for a specific field type as in your example), and have raised this with the team so we can look into improving this in a future release.

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