e071084ebe
govulncheck / govulncheck (push) Has been cancelled
Lint / golangci-lint (push) Has been cancelled
Run Tests / Unit Tests (push) Has been cancelled
Run Tests / Etcd Integration Tests (push) Has been cancelled
Harness (E2E) / Harnesses (mock LLM) (push) Has been cancelled
Harness (E2E) / Provider harnesses (live LLM conformance) (push) Has been cancelled
35 lines
1.4 KiB
JavaScript
35 lines
1.4 KiB
JavaScript
// Minimal JS for reactive form submissions
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
document.querySelectorAll('form[data-reactive]')?.forEach(function(form) {
|
|
form.addEventListener('submit', async function(e) {
|
|
e.preventDefault();
|
|
const formData = new FormData(form);
|
|
const params = {};
|
|
for (const [key, value] of formData.entries()) {
|
|
params[key] = value;
|
|
}
|
|
const action = form.getAttribute('action');
|
|
const method = form.getAttribute('method') || 'POST';
|
|
try {
|
|
const resp = await fetch(action, {
|
|
method,
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(params)
|
|
});
|
|
const data = await resp.json();
|
|
// Find or create a response container
|
|
let respDiv = form.querySelector('.js-response');
|
|
if (!respDiv) {
|
|
respDiv = document.createElement('div');
|
|
respDiv.className = 'js-response';
|
|
form.appendChild(respDiv);
|
|
}
|
|
respDiv.innerHTML = '<pre>' + JSON.stringify(data, null, 2) + '</pre>';
|
|
} catch (err) {
|
|
alert('Error: ' + err);
|
|
}
|
|
});
|
|
});
|
|
});
|