clear on the client-side again

This commit is contained in:
papuSpartan 2022-11-01 14:03:56 -05:00
parent 25de9df364
commit 401350cd59
2 changed files with 22 additions and 18 deletions

View File

@ -142,22 +142,33 @@ function selected_tab_id() {
}
function clear_prompt(_, _prompt_neg, confirmed, _token_counter) {
confirmed = false
function clear_prompt() {
if(confirm("Delete prompt?")) {
confirmed = true
} else {
return [_, _prompt_neg, confirmed, _token_counter]
}
if(selected_tab_id() == "tab_txt2img") {
update_token_counter("img2img_token_button")
let pos_prompt = gradioApp().querySelector("#txt2img_prompt > label > textarea");
let neg_prompt = gradioApp().querySelector("#txt2img_neg_prompt > label > textarea");
if (selected_tab_id() == "tab_txt2img") {
} else {
update_token_counter("txt2img_token_button")
pos_prompt = gradioApp().querySelector("#img2img_prompt > label > textarea");
neg_prompt = gradioApp().querySelector("#img2img_neg_prompt > label > textarea");
}
return [_, _prompt_neg, confirmed, _token_counter]
pos_prompt.value = ""
neg_prompt.value = ""
//update prompt values on server-side
pos_prompt.dispatchEvent(
new Event("input", {bubbles: true})
)
neg_prompt.dispatchEvent(
new Event("input", {bubbles: true})
)
return true
} else return false
}

View File

@ -400,19 +400,12 @@ def create_seed_inputs():
return seed, reuse_seed, subseed, reuse_subseed, subseed_strength, seed_resize_from_h, seed_resize_from_w, seed_checkbox
def clear_prompt(prompt, _prompt_neg, confirmed, _token_counter):
"""Given confirmation from a user on the client-side, go ahead with clearing prompt"""
if confirmed:
return ["", "", confirmed, update_token_counter("", 1)]
else:
return [prompt, _prompt_neg, confirmed, _token_counter]
def connect_clear_prompt(button, prompt, prompt_neg, _dummy_confirmed, token_counter):
"""Given clear button, prompt, and token_counter objects, setup clear prompt button click event"""
button.click(
_js="clear_prompt",
fn=clear_prompt,
fn=None,
inputs=[prompt, prompt_neg, _dummy_confirmed, token_counter],
outputs=[prompt, prompt_neg, _dummy_confirmed, token_counter],
)