dataTable/test/diagnostic.html

69 lines
2.7 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>AutoForm Diagnostic</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script type="importmap">
{
"imports": {
"@web/state": "../../state/src/index.js",
"@web/base": "../../base/src/index.js"
}
}
</script>
<script type="module">
import { Component, NewState, RefreshState } from '@web/state';
import '@web/base';
window.RefreshState = RefreshState;
window.DiagnosticState = NewState({
schema: [],
data: {}
});
window.runDiagnostic = async () => {
const form = document.getElementById('diagForm');
if (!form.state) form.state = NewState({ schema: [] });
console.log('--- STEP 1: TEXT ---');
DiagnosticState.schema = [{ id: 't1', name: 't1', label: '', type: 'text' }];
DiagnosticState.data = { t1: 'Hello World' };
form.state.schema = DiagnosticState.schema;
form.data = DiagnosticState.data;
RefreshState(form);
await new Promise(r => setTimeout(r, 200));
console.log('Input value:', form.querySelector('input')?.value);
console.log('--- STEP 2: TAGS ---');
DiagnosticState.schema = [{ id: 'tags', name: 'tags', label: '', type: 'TagsInput' }];
DiagnosticState.data = { tags: ['A', 'B'] };
form.state.schema = DiagnosticState.schema;
form.data = DiagnosticState.data;
RefreshState(form);
await new Promise(r => setTimeout(r, 200));
console.log('Tags count:', form.querySelectorAll('TagsInput button').length);
console.log('--- STEP 3: RADIO ---');
DiagnosticState.schema = [{ id: 'r1', name: 'r1', label: '', type: 'radio', options: ['Op1', 'Op2'] }];
DiagnosticState.data = { r1: 'Op2' };
form.state.schema = DiagnosticState.schema;
form.data = DiagnosticState.data;
RefreshState(form);
await new Promise(r => setTimeout(r, 200));
console.log('Radio Op2 checked:', form.querySelector('input[value="Op2"]')?.checked);
};
document.addEventListener('DOMContentLoaded', () => {
RefreshState(document.documentElement);
});
</script>
</head>
<body class="p-4">
<div style="width: 300px; border: 1px solid blue; min-height: 100px;">
<AutoForm id="diagForm" inline></AutoForm>
</div>
<button class="btn btn-danger mt-3" onclick="runDiagnostic()">START DIAGNOSTIC</button>
</body>
</html>