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

Is there a way to determine depth in nested forms? #4493

Open
1 task done
joesaunderson opened this issue Feb 10, 2025 · 1 comment
Open
1 task done

Is there a way to determine depth in nested forms? #4493

joesaunderson opened this issue Feb 10, 2025 · 1 comment

Comments

@joesaunderson
Copy link

Prerequisites

What theme are you using?

core

What is your question?

I am using nested forms, and would like to know is there a way to find out how "deep" I am.

Context - I would like to use headings (for accessibility) and would like to apply H1-H6 depending on how deep the form is.

Different approaches welcome.

@joesaunderson joesaunderson added needs triage Initial label given, to be assigned correct labels and assigned question labels Feb 10, 2025
@nickgros
Copy link
Contributor

nickgros commented Feb 14, 2025

You could wrap the ObjectField (or ObjectFieldTemplate) and include a React.Context that stores the current depth, and adds 1 in each instance.

You also might be able to parse the ID. Assuming your ID splits on _ and you don't use _ in your field names, the number of _ characters in the ID should map to the depth of the property.

You may need to tweak either of these approaches to also account for items in arrays, depending on your needs.

@nickgros nickgros added awaiting response and removed needs triage Initial label given, to be assigned correct labels and assigned labels Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants