# How to create complex dependent select attributes

**URL:** <https://community.hivepress.io/t/how-to-create-complex-dependent-select-attributes/14159>\
**Category:** HivePress\
**Tags:** code\
**Created:** [January 3, 2025, 10:56am UTC](https://community.hivepress.io/t/how-to-create-complex-dependent-select-attributes/14159 "2025-01-03T10:56:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elelelel](https://community.hivepress.io/letter_avatar_proxy/v4/letter/e/9dc877/32.png) [@elelelel](https://community.hivepress.io/u/elelelel)\
**Post date:** [January 3, 2025, 10:56am UTC](https://community.hivepress.io/t/how-to-create-complex-dependent-select-attributes/14159/1 "2025-01-03T10:56:20Z")

</div>

Hi, I would like to create dependent select attributes (2 or more attributes) like make, then model, then body type, etc.

I have read all of the other posts referring to the same dependent attribute feature, and am aware of the workaround using a parent-child attribute as shown in [this answer](https://community.hivepress.io/t/create-two-dependent-select-attributes/4872/5).

However, I’m wondering if anyone can give me some direction on how to do a custom implementation for this feature. Again, I am aware of the work around but I need more complex dependencies. Any rough or detailed guidance as to a viable custom approach would be very helpful.

Thank you.

---

<div class="post-metadata">

**Author:** ![ihor](https://community.hivepress.io/user_avatar/community.hivepress.io/ihor/32/5_2.png) [@ihor](https://community.hivepress.io/u/ihor)\
**Post date:** [January 6, 2025, 9:50pm UTC](https://community.hivepress.io/t/how-to-create-complex-dependent-select-attributes/14159/3 "2025-01-06T21:50:35Z")

</div>

Hi,

Unfortunately there’s no simple code snippet, but I can provide general guidance if you’re familiar with coding.

The easiest way would require adding custom JS and PHP code. The JS code, to which fields depend on which ones, and add/remove the HTML “required” attribute. For example, you can pass a custom parameter like “\_parent” to the field array of parameters (via the form hooks, e.g. for the listing form `hivepress/v1/forms/listing_update`), with the parent field name. Then, using `hivepress/v1/fields/field` hook, you can check if this parameter is passed (by checking `$field->get_args()`), and add a HTML attribute like data-parent=“parent\_field\_name\_here”. With JS, you can then listen to the parent field changes and if it changes, make the child field required or not (and optionally hide child fields or show them, this way the form content will depend on the selected parent field values).

Additionally, you can also check this logic on the back-end via the `hivepress/v1/forms/listing_update/errors` filter hook, otherwise with front-end-only logic (via JS), parent/child field requirements can be skipped if someone knows how to disable JS on a page.

Hope this helps

---

<div class="post-metadata">

**Author:** ![system](https://community.hivepress.io/user_avatar/community.hivepress.io/system/32/13990_2.png) [@system](https://community.hivepress.io/u/system)\
**Post date:** [February 5, 2025, 9:50pm UTC](https://community.hivepress.io/t/how-to-create-complex-dependent-select-attributes/14159/4 "2025-02-05T21:50:38Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
