-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sending input event via javascript to text area produces error messages in browser's console #2981
Comments
Here's the fix. That function that throws the error is not seeing the target when the event is dispatched manually. So when you make your event, you'll need to add the target. function(){
let elemTextArea = gradioApp().querySelector(#txt2img_prompt textarea)
// define event separately
let myEvent = new Event("input")
// update it's target to the element
Object.defineProperty(myEvent, "target", {value: elemTextArea})
// dispatch the event with a non null target
elemTextArea.dispatchEvent(myEvent)
} |
Ah. Thanks. That helps. I tried doing I guess than means this is not even gradio's fault and was just my code not creating events properly. |
Thanks @Gerschel and @AUTOMATIC1111! |
This also solves the annoying console error after completion, which was due to missing the target property See gradio-app/gradio#2981 for details
@abidlabs Is there an equivalent of:
in gradio 4? Both |
What specifically are you trying to do with this code snippet? |
@pngwn I'm trying to put it in a callback so that a javascript component (folium in this case) can write information onto the gradioverse, that I can then access in Gradio. |
I was running into the same issue with the folium component and found a way that might help you. In my use case I wanted to populate the lat and lng of a newly placed marker as a gradio input. I solved this with two scripts, first, by making a modified folium ClickForMarker function that on the placement of the marker, modifies the parent component with a new attribute containing the coordinates.
Second I added a js function the Gradio Block that would wait for the map iframe to load and then add an event listener to watch for mutation of the folium component and pull the coordinates attributes and fill in my chosen gradio.Textboxes.
Its is a bit hacky and probably not ideal but it works with getting coordinates out of folium iframe maps. This below code fragment,
was the secret sauce that I needed to get gradioverse to recognize the value of the updated gradio textbox. Other ways of updating that I tried would update visually but I found that gradio wouldn't acknowledge the updated values when trying to use them for processing. |
Describe the bug
The only way we've found so far to edit a gradio textarea from javascript is to create an "input" event.
The code below demonstrates this: left button just sets textarea content from javascript, right button sets content and creates an event, and bottom button copies textarea contents to label via gradio.
If you press left and then bottom button, the text "abc" is not copied to label. If you press right and then bottom button, the text "def" is copied to label. So the event is necessary.
The problem is whenever the event is sent I get a very unpleasant looking exception stack trace in browser. Since everything is obfuscated, I don't want to fix it myself client-size since then I'd have to exit the fix every time I update gradio.
Is there an existing issue for this?
Reproduction
Screenshot
No response
Logs
Severity
annoying
The text was updated successfully, but these errors were encountered: