Informel basic usage
by juliendelort
HTML
<script src="https://unpkg.com/informel"></script>
<inform-el>
<form>
<label>
First Name
<input type="text" name="firstName" />
</label>
<label>
Last Name
<input type="text" name="lastName" />
</label>
<button type="submit">Submit</button>
</form>
</inform-el>
<div id="result" />
<script>
document.querySelector("inform-el").addEventListener("inform-submit", ({ detail: { values } }) => {
document.querySelector('#result').textContent = JSON.stringify(values, null, '\t');
});
</script>
CSS
#result {
margin-top: 10px;
}
label {
display: block;
margin-bottom: 20px;
}
body {
background: #f6f8fa;
font-family: arial;
padding: 20px;
}
inform-el {
--error-margin: 5px 0;
}