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

InputAccordion duplicate elem_id handling #16381

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions modules/ui_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class InputAccordion(gr.Checkbox):
Actually just a hidden checkbox, but creates an accordion that follows and is followed by the state of the checkbox.
"""

accordion_id_set = set()
global_index = 0

def __init__(self, value, **kwargs):
Expand All @@ -99,6 +100,18 @@ def __init__(self, value, **kwargs):
self.accordion_id = f"input-accordion-{InputAccordion.global_index}"
InputAccordion.global_index += 1

if not InputAccordion.accordion_id_set:
from modules import script_callbacks
script_callbacks.on_script_unloaded(InputAccordion.reset)

if self.accordion_id in InputAccordion.accordion_id_set:
count = 1
while (unique_id := f'{self.accordion_id}-{count}') in InputAccordion.accordion_id_set:
count += 1
self.accordion_id = unique_id

InputAccordion.accordion_id_set.add(self.accordion_id)

kwargs_checkbox = {
**kwargs,
"elem_id": f"{self.accordion_id}-checkbox",
Expand Down Expand Up @@ -143,3 +156,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
def get_block_name(self):
return "checkbox"

@classmethod
def reset(cls):
cls.global_index = 0
cls.accordion_id_set.clear()