Comments (6)
@christianmagill is that the entire code you use to generate this field? Can you include the code used in the repeater as well?
The code as written currently yields the following config array on $documents->build()
, which looks correct to me:
Array
(
[key] => group_documents
[title] => Documents
[fields] => Array
(
[0] => Array
(
[type] => text
[name] => documents_title
[label] => Documents Title
[key] => field_documents_documents_title
)
[1] => Array
(
[type] => repeater
[name] => documents
[label] => Documents
[key] => field_documents_documents
[layout] => block
[button_label] => Add Document
[sub_fields] => Array
(
)
)
)
[location] =>
)
I'm also wondering if this is ACF Builder or if ACF itself is "helping" when it detects the group name at the beginning of the field name and is striping it off. I've not run into that functionality before though.
from acf-builder.
$documents = new FieldsBuilder( 'documents');
$documents
->addText('documents_title')
->addRepeater( 'documents', [
'layout' => 'block',
])
->addText('title')
->addFile('file')
->endRepeater()
->setLocation('post_type', '==', 'page');
acf_add_local_field_group( $documents->build() );
from acf-builder.
Ok so that yields:
Array
(
[key] => group_documents
[title] => Documents
[fields] => Array
(
[0] => Array
(
[type] => text
[name] => documents_title
[label] => Documents Title
[key] => field_documents_documents_title
)
[1] => Array
(
[type] => repeater
[name] => documents
[label] => Documents
[key] => field_documents_documents
[layout] => block
[button_label] => Add Document
[sub_fields] => Array
(
[0] => Array
(
[type] => text
[name] => title
[label] => Title
[key] => field_documents_documents_title
)
[1] => Array
(
[type] => file
[name] => file
[label] => File
[key] => field_documents_documents_file
)
)
)
)
)
So you can see we end up with two fields with the same key: field_documents_documents_title
which is what your screenshot also says. There isn't really a way to avoid this. ACF Builder attempts to use a combination of the group name, field name and any ancestor field names to automatically build a "unique" field key.
I'm thinking I should add some sort of duplicate key exception maybe, so you'd be made aware of this right away.
If you removed the "documents_" string from the field name it would fix this issue:
$documents = new FieldsBuilder( 'documents');
$documents
->addText('title')
->addRepeater( 'documents', [
'layout' => 'block',
])
->addText('title')
->addFile('file')
->endRepeater()
->setLocation('post_type', '==', 'page');
Yields:
Array
(
[key] => group_documents
[title] => Documents
[fields] => Array
(
[0] => Array
(
[type] => text
[name] => title
[label] => Title
[key] => field_documents_title
)
[1] => Array
(
[type] => repeater
[name] => documents
[label] => Documents
[key] => field_documents_documents
[layout] => block
[button_label] => Add Document
[sub_fields] => Array
(
[0] => Array
(
[type] => text
[name] => title
[label] => Title
[key] => field_documents_documents_title
)
[1] => Array
(
[type] => file
[name] => file
[label] => File
[key] => field_documents_documents_file
)
)
)
)
)
Alternatively you could add a custom key to the title field in the repeater:
$documents = new FieldsBuilder( 'documents');
$documents
->addText('documents_title')
->addRepeater( 'documents', [
'layout' => 'block',
])
->addText('title')
->setKey('document_title')
->addFile('file')
->endRepeater()
That yields:
Array
(
[key] => group_documents
[title] => Documents
[fields] => Array
(
[0] => Array
(
[type] => text
[name] => documents_title
[label] => Documents Title
[key] => field_documents_documents_title
)
[1] => Array
(
[type] => repeater
[name] => documents
[label] => Documents
[key] => field_documents_documents
[layout] => block
[button_label] => Add Document
[sub_fields] => Array
(
[0] => Array
(
[type] => text
[name] => title
[label] => Title
[key] => field_documents_documents_document_title
)
[1] => Array
(
[type] => file
[name] => file
[label] => File
[key] => field_documents_documents_file
)
)
)
)
)
from acf-builder.
Probably the alternative approach is the way to go. I don't want "title" at the root level to avoid clashing with other possible groups.
Are there character limits to how long a key can be? How about including "group" in the naming to differentiate?
from acf-builder.
I have run into an issue before when the SUHOISN PHP module is enabled and there is a limit on POST var names. See this stack overflow link
Maybe there is a better word than title for both, such as document name or document headline or maybe even document section title.
Or maybe staying consistent and inside the repeater and name those fields document_title and document_file, that would generate:
Array
(
[key] => group_documents
[title] => Documents
[fields] => Array
(
[0] => Array
(
[type] => text
[name] => documents_title
[label] => Documents Title
[key] => field_documents_documents_title
)
[1] => Array
(
[type] => repeater
[name] => documents
[label] => Documents
[key] => field_documents_documents
[layout] => block
[button_label] => Add Document
[sub_fields] => Array
(
[0] => Array
(
[type] => text
[name] => document_title
[label] => Document Title
[key] => field_documents_documents_document_title
)
[1] => Array
(
[type] => file
[name] => document_file
[label] => Document File
[key] => field_documents_documents_document_file
)
)
)
)
)
from acf-builder.
Cool, I see your point...
I probably need to revisit my naming conventions in general to stop these kind of issues.
Much thanks for your help!
from acf-builder.
Related Issues (20)
- Add empty conditional info to docs HOT 1
- Will ACF 6 be supported? HOT 1
- Invalid argument supplied for foreach() in .../stoutlogic/acf-builder/src/Transform/RecursiveTransform.php on line 34 (v1.12.0) HOT 3
- ACF 6 repeater pagination not working HOT 1
- Image field return_format returns an ID instead of array or URL HOT 2
- Is there documentation about get_field_partial? HOT 1
- post_object field empty when using WPML language HOT 5
- Incorrect typing/interface? HOT 6
- Dynamically populate a field’s choices based on another field HOT 1
- ACF Builder fails silently - Sage 10 HOT 4
- Can not determine field key for repeater's collapsed value HOT 2
- ACF Extended Compatible? HOT 4
- ❤️ FAQ: difference between acf-builder and extended-acf
- Label placement 'left' doesn't work for options pages
- Feature Request - Update Default Values for Fields in Partials HOT 1
- WP-CLI Error : Segmentation fault HOT 1
- Repeater is not Working HOT 9
- ACF setLocation('page_template') Not Working HOT 2
- Migrating excisting field keys HOT 1
- Issue with WPML may require moving away from acf-builder. Is there a way to get JSON/PHP to import into ACF Pro UI? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from acf-builder.