import { Story, Meta, html, Preview } from '@open-wc/demoing-storybook'; import { Required, MaxLength, loadDefaultFeedbackMessages } from '@lion/validate'; import '@lion/fieldset/lion-fieldset.js'; import '@lion/input/lion-input.js'; import '@lion/form/lion-form.js'; # Form Examples A form can have multiple nested fieldsets. {html`
`}
## Form Submit / Reset You can control whether a form gets submitted based on validation states. Same thing goes for resetting the inputs to the original state. Be sure to call `serializedValue` when a you want to submit a form. This value automatically filters out disabled children and makes sure the values that are retrieved can be transmitted over a wire. (for instance, an input-date with a modelValue of type `Date` will be serialized to an iso formatted string). > Note: Offering a reset button is a bad practice in terms of accessibility. This button is only used here to demonstrate the `serializeGroup()` method. {() => { loadDefaultFeedbackMessages(); const submit = () => { const form = document.querySelector('#form2'); if (!form.hasFeedbackFor.includes('error')) { document.getElementById('form2_output').innerText = JSON.stringify(form.serializedValue); document.querySelector('#form2').resetGroup(); } }; return html`
          
`; }}
## Serialize in a multistep form In a multistep form (consisting of multiple forms) it might be handy to wrap the serialized output with the name of the form. {() => { loadDefaultFeedbackMessages(); const serializeWithName = (formId, outputId) => { const form = document.getElementById(formId); if (!form.hasFeedbackFor.includes('error')) { const output = { [form.name]: form.serializedValue }; document.getElementById(outputId).innerText = JSON.stringify(output); } }; return html`

        

        
`; }}