mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2025-01-01 12:25:06 +08:00
InputAccordion duplicate elem_id handling (#16381)
This commit is contained in:
parent
59481435f4
commit
5206b938ef
@ -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):
|
||||
@ -99,6 +100,18 @@ class InputAccordion(gr.Checkbox):
|
||||
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",
|
||||
@ -143,3 +156,7 @@ class InputAccordion(gr.Checkbox):
|
||||
def get_block_name(self):
|
||||
return "checkbox"
|
||||
|
||||
@classmethod
|
||||
def reset(cls):
|
||||
cls.global_index = 0
|
||||
cls.accordion_id_set.clear()
|
||||
|
Loading…
Reference in New Issue
Block a user