gradio icon indicating copy to clipboard operation
gradio copied to clipboard

Add "Confirmation Dialogue" before leaving the Gradio Playground

Open apolinario opened this issue 2 years ago • 4 comments

  • [x] I have searched to see if a similar issue already exists.

Is your feature request related to a problem? Please describe.
If someone is deep into using the playground to prototype/play with possibilities for a gradio design, can be frustrating that a misclick closes a tab or returns to a previous page.

Describe the solution you'd like
As this handles inputs that can be edited for a bit, I'd suggest to add a Leave site? confirmation to the Playground ge image

Additional context
Obviously this happened to me after spending some time in the playground playing with building the layout of an app 😅

apolinario avatar Nov 27 '23 12:11 apolinario

You can do it using this pattern:

def onIfaceLoadedJS():
    return '''(...args) => {
        window.addEventListener('beforeunload', (event) => {
            event.returnValue = 'Are you sure you want to close?';
        });
        return [...args];
    }'''
iface.load(fn=lambda: None, inputs=[], outputs=[], js=onIfaceLoadedJS())
iface.launch(...)

light-and-ray avatar Jun 04 '24 10:06 light-and-ray

That's cool @light-and-ray, but ideally this is a feature of the playground site itself (vs. the app being developed) imo

apolinario avatar Jun 04 '24 17:06 apolinario

Hi there. getting this error Error TypeError: Cannot convert undefined or null to object Would you know how to fix this.

import gradio as gr

def onIfaceLoadedJS():
    return '''() => {
        console.log('JavaScript function loaded');
        window.addEventListener('beforeunload', (event) => {
            event.returnValue = 'Are you sure you want to close?';
        });
    }'''

def hello_world():
    return 'This is a warning message.'

with gr.Blocks() as demo:
    md = gr.Markdown()
    demo.load(fn=hello_world, inputs=[], outputs=[md], js=onIfaceLoadedJS())
demo.queue().launch()

delonleo avatar Jun 14 '24 10:06 delonleo

You have forgotten ...args in js code

light-and-ray avatar Jun 14 '24 12:06 light-and-ray