diff --git a/javascript/ui.js b/javascript/ui.js index be47ec64..00e80fd6 100644 --- a/javascript/ui.js +++ b/javascript/ui.js @@ -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 + } diff --git a/modules/ui.py b/modules/ui.py index 447722cd..f43e79ab 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -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], )