Serializer.js/tests/templates/test.gohtml

56 lines
1.4 KiB
Plaintext

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
<style>
form > group{
margin: 10px 0;
display: block;
}
group * {
display: block;
}
</style>
<script src="/static/serializer.js"></script>
</head>
<body>
<form id="testform">
{{ range $k, $p := . }}
{{ if $p }}
<group name="[{{ $k }}]">
<input name="name" type="text" value="{{ $p.Name }}">
<input name="surname" type="text" value="{{ $p.Surname }}">
<input name="age" type="number" value="{{ $p.Age }}">
<input name="birth_date" type="date" value="{{ $p.BirthDate.Format "2006-01-02" }}">
{{ range $p.Languages }}
<group name="[]languages">
<label>
<input name="language" type="text" value="{{ .Language }}">
</label>
<input name="native" type="checkbox" {{ if .Native }} checked {{ end }}>
<input name="skill_level" type="number" value="{{ .SkillLevel }}">
</group>
{{ end }}
</group>
{{ end }}
{{ end }}
</form>
<script>
let f = document.getElementById("testform"),
s = new Serializer(f);
fetch("/", {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(s.serialize())
}).then(() => {
window.close()
})
</script>
</body>
</html>