Skip to content

Commit

Permalink
update sending input event in java script to not cause exception in b…
Browse files Browse the repository at this point in the history
  • Loading branch information
AUTOMATIC1111 committed Jan 17, 2023
1 parent aede265 commit 38b7186
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 2 additions & 3 deletions javascript/edit-attention.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ addEventListener('keydown', (event) => {
target.selectionStart = selectionStart;
target.selectionEnd = selectionEnd;
}
// Since we've modified a Gradio Textbox component manually, we need to simulate an `input` DOM event to ensure its
// internal Svelte data binding remains in sync.
target.dispatchEvent(new Event("input", { bubbles: true }));

updateInput(target)
});
2 changes: 1 addition & 1 deletion javascript/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function install_extension_from_index(button, url){

textarea = gradioApp().querySelector('#extension_to_install textarea')
textarea.value = url
textarea.dispatchEvent(new Event("input", { bubbles: true }))
updateInput(textarea)

gradioApp().querySelector('#install_extension_button').click()
}
8 changes: 8 additions & 0 deletions javascript/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,11 @@ function restart_reload(){

return []
}

// Simulate an `input` DOM event for Gradio Textbox component. Needed after you edit its contents in javascript, otherwise your edits
// will only visible on web page and not sent to python.
function updateInput(target){
let e = new Event("input", { bubbles: true })
Object.defineProperty(e, "target", {value: target})
target.dispatchEvent(e);
}

0 comments on commit 38b7186

Please sign in to comment.