Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created March 24, 2023 12:34
Show Gist options
  • Save bennadel/17436269b6b75b7f3c3c75457a342a15 to your computer and use it in GitHub Desktop.
Save bennadel/17436269b6b75b7f3c3c75457a342a15 to your computer and use it in GitHub Desktop.
Trying To Get ChatGPT 4 To Solve My Hotwire Form Submission Problem
document.addEventListener("DOMContentLoaded", function() {
// Get the form element
const form = document.querySelector("form");
// Listen for the Turbo Drive form submission event
form.addEventListener("turbo:submit-end", function() {
// Scroll the form back into view
form.scrollIntoView();
});
});
document.addEventListener("turbo:submit-end", function(event) {
const form = event.target.querySelector("form");
if (form) {
// Scroll the form back into view after a short delay
setTimeout(function() {
form.scrollIntoView();
}, 0);
}
});
document.addEventListener("DOMContentLoaded", function() {
// Get the form element
const form = document.querySelector("form");
// Listen for the Turbo Drive form submission event
form.addEventListener("turbo:submit-end", function() {
// Scroll the form back into view after a short delay
setTimeout(function() {
form.scrollIntoView();
}, 0);
});
});
document.addEventListener("turbo:submit-end", function(event) {
const form = event.target;
// Scroll the form back into view after a short delay
setTimeout(function() {
form.scrollIntoView();
}, 0);
});
document.addEventListener("turbo:submit-end", function(event) {
const form = event.detail.formSubmission.formElement;
// Scroll the form back into view after a short delay
setTimeout(function() {
form.scrollIntoView();
}, 0);
});
document.addEventListener("turbo:load", function(event) {
const form = event.target.querySelector("form");
if (form) {
// Scroll the form back into view after a short delay
setTimeout(function() {
form.scrollIntoView();
}, 0);
}
});
document.addEventListener("turbo:load", function(event) {
const form = event.target.querySelector("form[data-turbo-permanent]");
if (form) {
// Scroll the form back into view after a short delay
setTimeout(function() {
form.scrollIntoView();
}, 0);
}
});
document.addEventListener("turbo:load", function(event) {
const container = event.target.querySelector("[data-turbo-permanent]");
if (container) {
const form = container.querySelector("form");
if (form) {
// Scroll the form back into view after a short delay
setTimeout(function() {
form.scrollIntoView();
}, 0);
}
}
});
document.addEventListener("turbo:submit-end", function(event) {
const form = event.target.querySelector("form");
if (form) {
// Scroll the form back into view after a short delay
setTimeout(function() {
form.scrollIntoView();
}, 0);
}
});
document.addEventListener("turbo:load", function(event) {
const form = event.target.querySelector("form");
if (form) {
// Scroll the form back into view after a short delay
setTimeout(function() {
form.scrollIntoView();
}, 0);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment