Skip to content

Commit

Permalink
InputAccordion duplicate elem_id handling (AUTOMATIC1111#16381)
Browse files Browse the repository at this point in the history
  • Loading branch information
w-e-w authored Oct 29, 2024
1 parent 5948143 commit 5206b93
Showing 1 changed file with 17 additions and 0 deletions.
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()

0 comments on commit 5206b93

Please sign in to comment.