diff --git a/packages/form-system/stories/15-features-overview.stories.mdx b/packages/form-system/stories/15-features-overview.stories.mdx index 10fed8d19..ff84977f0 100644 --- a/packages/form-system/stories/15-features-overview.stories.mdx +++ b/packages/form-system/stories/15-features-overview.stories.mdx @@ -4,6 +4,7 @@ import '@lion/fieldset/lion-fieldset.js'; import '@lion/form/lion-form.js'; import '@lion/input-amount/lion-input-amount.js'; import '@lion/input-date/lion-input-date.js'; +import '@lion/input-datepicker/lion-input-datepicker.js'; import '@lion/input-email/lion-input-email.js'; import '@lion/input-iban/lion-input-iban.js'; import '@lion/input-range/lion-input-range.js'; @@ -28,25 +29,35 @@ For usage and installation please see the appropriate packages. - {html` + {() => { + Required.getMessage = () => 'Please enter a value'; + return html`
- - + + + + + @@ -101,7 +112,7 @@ For usage and installation please see the appropriate packages. step="0.1" label="Input range" > - + @@ -118,7 +129,7 @@ For usage and installation please see the appropriate packages.
- `} + `;}}
@@ -129,6 +140,7 @@ import '@lion/fieldset/lion-fieldset.js'; import '@lion/form/lion-form.js'; import '@lion/input-amount/lion-input-amount.js'; import '@lion/input-date/lion-input-date.js'; +import '@lion/input-datepicker/lion-input-datepicker.js'; import '@lion/input-email/lion-input-email.js'; import '@lion/input-iban/lion-input-iban.js'; import '@lion/input-range/lion-input-range.js'; diff --git a/packages/form-system/stories/17-Validation-Examples.stories.mdx b/packages/form-system/stories/17-Validation-Examples.stories.mdx index 3fd22e2a9..93e24387a 100644 --- a/packages/form-system/stories/17-Validation-Examples.stories.mdx +++ b/packages/form-system/stories/17-Validation-Examples.stories.mdx @@ -29,8 +29,10 @@ import { ## Required Validator -The required validator can be put onto every form field element and will make sure that element is not empty. -For an input that may mean that it is not an empty string while for a checkbox group it means at least one checkbox needs to be checked. +The required validator can be put onto every form field element and will make sure that element is +not empty. +For an input that may mean that it is not an empty string, +while for a checkbox group it means at least one checkbox needs to be checked. {html` diff --git a/packages/form-system/stories/40-System-creating-a-custom-field.stories.mdx b/packages/form-system/stories/40-System-creating-a-custom-field.stories.mdx index c18fb904a..f0870739c 100644 --- a/packages/form-system/stories/40-System-creating-a-custom-field.stories.mdx +++ b/packages/form-system/stories/40-System-creating-a-custom-field.stories.mdx @@ -26,7 +26,7 @@ it has a tabindex=“0” applied. Now we want to integrate the slider in our form framework to enrich the user interface, get validation support and get all the other [benefits of LionField](/?path=/docs/forms-system-overview--page). -We start of by creating a component `` that extends from `LionField`. +We start by creating a component `` that extends from `LionField`. Then we follow the steps below: #### 1. Add your interaction element as ‘input slot' diff --git a/packages/form-system/stories/fieldset-examples.stories.mdx b/packages/form-system/stories/fieldset-examples.stories.mdx index 00586fa41..ca7ed46f9 100644 --- a/packages/form-system/stories/fieldset-examples.stories.mdx +++ b/packages/form-system/stories/fieldset-examples.stories.mdx @@ -298,7 +298,7 @@ Alternatively you can also let the fieldset validator be dependent on the error Simply loop over the formElements inside your Validator's `execute` method: ```js -this.formElementsArray.some(el => el.hasFeedbackFor.includes('error')); +this.formElements.some(el => el.hasFeedbackFor.includes('error')); ``` ### Validating multiple fieldsets diff --git a/packages/form-system/stories/form-examples.stories.mdx b/packages/form-system/stories/form-examples.stories.mdx index 1cd2ceac4..7a3a85f0d 100644 --- a/packages/form-system/stories/form-examples.stories.mdx +++ b/packages/form-system/stories/form-examples.stories.mdx @@ -1,4 +1,4 @@ -import { Story, Meta, html } from '@open-wc/demoing-storybook'; +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'; @@ -10,6 +10,7 @@ import '@lion/form/lion-form.js'; A form can have multiple nested fieldsets. + {html` @@ -25,48 +26,38 @@ 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')) { - console.log(form.serializeGroup()); - form.resetGroup(); + document.getElementById('form2_output').innerText = JSON.stringify(form.serializedValue); + document.querySelector('#form2').resetGroup(); } }; return html` @@ -85,58 +76,65 @@ Same thing goes for resetting the inputs to the original state. .validators=${[new Required(), new MaxLength(15)]} > + + - -

- A reset button should never be offered to users. This button is only used here to - demonstrate the functionality. -

+
+          
`; }}
+
-```js -import { Required, MaxLength } from '@lion/validate' -const submit = () => { - const form = document.querySelector('#form2'); - if (!form.hasFeedbackFor.includes('error')) { - console.log(form.serializeGroup()); - form.resetGroup(); - } -}; -``` -```html - -
- - - - - - - - -

- A reset button should never be offered to users. This button is only used here to - demonstrate the functionality. -

-
-
-``` +## 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` +
+ + +

+        
+
+ + +

+        
+ `; + }} +
+
diff --git a/packages/form-system/test/form-integrations.test.js b/packages/form-system/test/form-integrations.test.js index 602cf16ba..6db704d3d 100644 --- a/packages/form-system/test/form-integrations.test.js +++ b/packages/form-system/test/form-integrations.test.js @@ -3,7 +3,7 @@ import './helpers/umbrella-form.js'; // Test umbrella form describe('Form Integrations', () => { - it.skip('".serializedValue" returns all non disabled fields based on form structure', async () => { + it('".serializedValue" returns all non disabled fields based on form structure', async () => { const el = await fixture( html`