@digigov/form 0.13.2 → 1.0.0-6b93ebf2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Field/FieldBase.js +2 -2
- package/Field/FieldBaseContainer.js +8 -8
- package/Field/FieldConditional.js +2 -2
- package/Field/utils.js +6 -6
- package/FieldArray/__stories__/Default.js +2 -2
- package/FieldArray/__stories__/WithExactLength.js +2 -2
- package/FieldArray/index.js +3 -3
- package/FieldObject/index.d.ts +1 -1
- package/FieldObject/index.js +5 -5
- package/Fieldset/FieldsetWithContext.js +4 -4
- package/Fieldset/index.d.ts +1 -1
- package/Fieldset/index.js +2 -2
- package/Fieldset/types.d.ts +2 -2
- package/FormBuilder/FormBuilder.js +5 -5
- package/FormBuilder/FormBuilder.mdx +32 -45
- package/FormBuilder/__stories__/Default.js +2 -2
- package/MultiplicityField/MultiplicityField.mdx +277 -267
- package/MultiplicityField/__stories__/Default.js +2 -2
- package/MultiplicityField/__stories__/PreviewDisplay.js +8 -8
- package/MultiplicityField/__stories__/WithExactLength.js +2 -2
- package/MultiplicityField/__stories__/WithMaxLength.js +2 -2
- package/MultiplicityField/__stories__/WithMinAndMaxLength.js +2 -2
- package/MultiplicityField/__stories__/WithMinLength.js +2 -2
- package/MultiplicityField/add-objects.js +6 -6
- package/MultiplicityField/index.d.ts +2 -2
- package/MultiplicityField/index.js +7 -7
- package/Questions/Questions.js +2 -2
- package/Questions/Step/ReviewStep.js +8 -8
- package/Questions/Step/Step.js +2 -2
- package/Questions/Step/StepArrayReview.js +10 -10
- package/Questions/Step/StepDescription.js +2 -2
- package/Questions/Step/StepForm.d.ts +1 -1
- package/Questions/Step/StepForm.js +6 -6
- package/Questions/Step/StepTitle.js +5 -3
- package/Questions/Step/getAddMoreFields.d.ts +1 -1
- package/Questions/__snapshots__/index.spec.tsx.snap +9 -9
- package/Questions/__stories__/Default.js +6 -6
- package/Questions/index.mdx +41 -44
- package/Questions/index.spec.js +2 -2
- package/create-simple-form.mdx +258 -237
- package/es/Field/FieldBase.js +1 -1
- package/es/Field/FieldBaseContainer.js +6 -6
- package/es/Field/FieldConditional.js +1 -1
- package/es/Field/utils.js +5 -5
- package/es/FieldArray/__stories__/Default.js +1 -1
- package/es/FieldArray/__stories__/WithExactLength.js +1 -1
- package/es/FieldArray/index.js +2 -2
- package/es/FieldObject/index.js +3 -3
- package/es/Fieldset/FieldsetWithContext.js +2 -2
- package/es/Fieldset/index.js +1 -1
- package/es/FormBuilder/FormBuilder.js +3 -3
- package/es/FormBuilder/FormBuilder.mdx +32 -45
- package/es/FormBuilder/__stories__/Default.js +1 -1
- package/es/MultiplicityField/MultiplicityField.mdx +277 -267
- package/es/MultiplicityField/__stories__/Default.js +1 -1
- package/es/MultiplicityField/__stories__/PreviewDisplay.js +7 -7
- package/es/MultiplicityField/__stories__/WithExactLength.js +1 -1
- package/es/MultiplicityField/__stories__/WithMaxLength.js +1 -1
- package/es/MultiplicityField/__stories__/WithMinAndMaxLength.js +1 -1
- package/es/MultiplicityField/__stories__/WithMinLength.js +1 -1
- package/es/MultiplicityField/add-objects.js +3 -3
- package/es/MultiplicityField/index.js +5 -5
- package/es/Questions/Questions.js +1 -1
- package/es/Questions/Step/ReviewStep.js +5 -5
- package/es/Questions/Step/Step.js +1 -1
- package/es/Questions/Step/StepArrayReview.js +7 -7
- package/es/Questions/Step/StepDescription.js +1 -1
- package/es/Questions/Step/StepForm.js +5 -5
- package/es/Questions/Step/StepTitle.js +5 -4
- package/es/Questions/__snapshots__/index.spec.tsx.snap +9 -9
- package/es/Questions/__stories__/Default.js +4 -4
- package/es/Questions/index.mdx +41 -44
- package/es/Questions/index.spec.js +1 -1
- package/es/create-simple-form.mdx +258 -237
- package/es/index.mdx +13 -6
- package/es/inputs/AutoComplete/__stories__/Default.js +3 -3
- package/es/inputs/AutoComplete/index.js +1 -1
- package/es/inputs/Checkboxes/__stories__/Conditional.js +1 -1
- package/es/inputs/Checkboxes/__stories__/Default.js +1 -1
- package/es/inputs/Checkboxes/__stories__/WithDivider.js +2 -2
- package/es/inputs/Checkboxes/index.js +3 -3
- package/es/inputs/DateInput/__stories__/Default.js +1 -1
- package/es/inputs/DateInput/index.js +1 -1
- package/es/inputs/FileInput/__stories__/Default.js +1 -1
- package/es/inputs/FileInput/index.js +5 -5
- package/es/inputs/Input/__stories__/AFM.js +1 -1
- package/es/inputs/Input/__stories__/Boolean.js +1 -1
- package/es/inputs/Input/__stories__/Default.js +1 -1
- package/es/inputs/Input/__stories__/IBAN.js +1 -1
- package/es/inputs/Input/__stories__/Integer.js +1 -1
- package/es/inputs/Input/__stories__/MobilePhone.js +1 -1
- package/es/inputs/Input/__stories__/PhoneNumber.js +1 -1
- package/es/inputs/Input/__stories__/PostalCode.js +1 -1
- package/es/inputs/Input/__stories__/TextWithCharacterLimit.js +1 -1
- package/es/inputs/Input/index.js +1 -1
- package/es/inputs/Label/__stories__/Default.js +1 -1
- package/es/inputs/Label/index.js +3 -3
- package/es/inputs/OtpInput/__stories__/Default.js +1 -1
- package/es/inputs/OtpInput/index.js +1 -1
- package/es/inputs/Radio/__stories__/Conditional.js +1 -1
- package/es/inputs/Radio/__stories__/Default.js +1 -1
- package/es/inputs/Radio/__stories__/WithDivider.js +2 -2
- package/es/inputs/Radio/index.js +4 -4
- package/es/inputs/Select/__stories__/Default.js +1 -1
- package/es/installation.mdx +12 -16
- package/es/utils.js +1 -1
- package/es/validators/index.js +2 -2
- package/esm/Field/FieldBase.js +1 -1
- package/esm/Field/FieldBaseContainer.js +6 -6
- package/esm/Field/FieldConditional.js +1 -1
- package/esm/Field/utils.js +5 -5
- package/esm/FieldArray/__stories__/Default.js +1 -1
- package/esm/FieldArray/__stories__/WithExactLength.js +1 -1
- package/esm/FieldArray/index.js +2 -2
- package/esm/FieldObject/index.js +3 -3
- package/esm/Fieldset/FieldsetWithContext.js +2 -2
- package/esm/Fieldset/index.js +1 -1
- package/esm/FormBuilder/FormBuilder.js +3 -3
- package/esm/FormBuilder/FormBuilder.mdx +32 -45
- package/esm/FormBuilder/__stories__/Default.js +1 -1
- package/esm/MultiplicityField/MultiplicityField.mdx +277 -267
- package/esm/MultiplicityField/__stories__/Default.js +1 -1
- package/esm/MultiplicityField/__stories__/PreviewDisplay.js +7 -7
- package/esm/MultiplicityField/__stories__/WithExactLength.js +1 -1
- package/esm/MultiplicityField/__stories__/WithMaxLength.js +1 -1
- package/esm/MultiplicityField/__stories__/WithMinAndMaxLength.js +1 -1
- package/esm/MultiplicityField/__stories__/WithMinLength.js +1 -1
- package/esm/MultiplicityField/add-objects.js +3 -3
- package/esm/MultiplicityField/index.js +5 -5
- package/esm/Questions/Questions.js +1 -1
- package/esm/Questions/Step/ReviewStep.js +5 -5
- package/esm/Questions/Step/Step.js +1 -1
- package/esm/Questions/Step/StepArrayReview.js +7 -7
- package/esm/Questions/Step/StepDescription.js +1 -1
- package/esm/Questions/Step/StepForm.js +5 -5
- package/esm/Questions/Step/StepTitle.js +5 -4
- package/esm/Questions/__snapshots__/index.spec.tsx.snap +9 -9
- package/esm/Questions/__stories__/Default.js +4 -4
- package/esm/Questions/index.mdx +41 -44
- package/esm/Questions/index.spec.js +1 -1
- package/esm/create-simple-form.mdx +258 -237
- package/esm/index.js +1 -1
- package/esm/index.mdx +13 -6
- package/esm/inputs/AutoComplete/__stories__/Default.js +3 -3
- package/esm/inputs/AutoComplete/index.js +1 -1
- package/esm/inputs/Checkboxes/__stories__/Conditional.js +1 -1
- package/esm/inputs/Checkboxes/__stories__/Default.js +1 -1
- package/esm/inputs/Checkboxes/__stories__/WithDivider.js +2 -2
- package/esm/inputs/Checkboxes/index.js +3 -3
- package/esm/inputs/DateInput/__stories__/Default.js +1 -1
- package/esm/inputs/DateInput/index.js +1 -1
- package/esm/inputs/FileInput/__stories__/Default.js +1 -1
- package/esm/inputs/FileInput/index.js +5 -5
- package/esm/inputs/Input/__stories__/AFM.js +1 -1
- package/esm/inputs/Input/__stories__/Boolean.js +1 -1
- package/esm/inputs/Input/__stories__/Default.js +1 -1
- package/esm/inputs/Input/__stories__/IBAN.js +1 -1
- package/esm/inputs/Input/__stories__/Integer.js +1 -1
- package/esm/inputs/Input/__stories__/MobilePhone.js +1 -1
- package/esm/inputs/Input/__stories__/PhoneNumber.js +1 -1
- package/esm/inputs/Input/__stories__/PostalCode.js +1 -1
- package/esm/inputs/Input/__stories__/TextWithCharacterLimit.js +1 -1
- package/esm/inputs/Input/index.js +1 -1
- package/esm/inputs/Label/__stories__/Default.js +1 -1
- package/esm/inputs/Label/index.js +3 -3
- package/esm/inputs/OtpInput/__stories__/Default.js +1 -1
- package/esm/inputs/OtpInput/index.js +1 -1
- package/esm/inputs/Radio/__stories__/Conditional.js +1 -1
- package/esm/inputs/Radio/__stories__/Default.js +1 -1
- package/esm/inputs/Radio/__stories__/WithDivider.js +2 -2
- package/esm/inputs/Radio/index.js +4 -4
- package/esm/inputs/Select/__stories__/Default.js +1 -1
- package/esm/installation.mdx +12 -16
- package/esm/utils.js +1 -1
- package/esm/validators/index.js +2 -2
- package/index.mdx +13 -6
- package/inputs/AutoComplete/__stories__/Default.js +4 -4
- package/inputs/AutoComplete/index.d.ts +2 -2
- package/inputs/AutoComplete/index.js +2 -2
- package/inputs/Checkboxes/__stories__/Conditional.js +2 -2
- package/inputs/Checkboxes/__stories__/Default.js +2 -2
- package/inputs/Checkboxes/__stories__/WithDivider.js +3 -3
- package/inputs/Checkboxes/index.d.ts +1 -1
- package/inputs/Checkboxes/index.js +4 -4
- package/inputs/DateInput/__stories__/Default.js +2 -2
- package/inputs/DateInput/index.js +2 -2
- package/inputs/FileInput/__stories__/Default.js +2 -2
- package/inputs/FileInput/index.js +5 -5
- package/inputs/Input/__stories__/AFM.js +2 -2
- package/inputs/Input/__stories__/Boolean.js +2 -2
- package/inputs/Input/__stories__/Default.js +2 -2
- package/inputs/Input/__stories__/IBAN.js +2 -2
- package/inputs/Input/__stories__/Integer.js +2 -2
- package/inputs/Input/__stories__/MobilePhone.js +2 -2
- package/inputs/Input/__stories__/PhoneNumber.js +2 -2
- package/inputs/Input/__stories__/PostalCode.js +2 -2
- package/inputs/Input/__stories__/TextWithCharacterLimit.js +2 -2
- package/inputs/Input/index.js +1 -1
- package/inputs/Label/__stories__/Default.js +2 -2
- package/inputs/Label/index.js +4 -4
- package/inputs/OtpInput/__stories__/Default.js +2 -2
- package/inputs/OtpInput/index.js +1 -1
- package/inputs/Radio/__stories__/Conditional.js +2 -2
- package/inputs/Radio/__stories__/Default.js +2 -2
- package/inputs/Radio/__stories__/WithDivider.js +3 -3
- package/inputs/Radio/index.d.ts +1 -1
- package/inputs/Radio/index.js +7 -7
- package/inputs/Select/__stories__/Default.js +2 -2
- package/inputs/Select/index.d.ts +1 -1
- package/installation.mdx +12 -16
- package/package.json +5 -5
- package/src/Field/FieldBase.tsx +1 -1
- package/src/Field/FieldBaseContainer.tsx +7 -7
- package/src/Field/FieldConditional.tsx +1 -1
- package/src/Field/index.tsx +1 -1
- package/src/Field/utils.ts +7 -7
- package/src/FieldArray/FieldArray.stories.js +1 -1
- package/src/FieldArray/__stories__/Default.tsx +1 -1
- package/src/FieldArray/__stories__/WithExactLength.tsx +1 -1
- package/src/FieldArray/index.tsx +3 -3
- package/src/FieldObject/index.tsx +6 -6
- package/src/Fieldset/FieldsetWithContext.tsx +3 -3
- package/src/Fieldset/index.tsx +5 -5
- package/src/Fieldset/types.tsx +3 -3
- package/src/FormBuilder/FormBuilder.mdx +32 -45
- package/src/FormBuilder/FormBuilder.stories.js +1 -1
- package/src/FormBuilder/FormBuilder.tsx +4 -4
- package/src/FormBuilder/__stories__/Default.tsx +1 -1
- package/src/MultiplicityField/MultiplicityField.mdx +277 -267
- package/src/MultiplicityField/MultiplicityField.stories.js +1 -1
- package/src/MultiplicityField/__stories__/Default.tsx +1 -1
- package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +14 -14
- package/src/MultiplicityField/__stories__/WithExactLength.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithMaxLength.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithMinAndMaxLength.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithMinLength.tsx +1 -1
- package/src/MultiplicityField/add-objects.tsx +3 -3
- package/src/MultiplicityField/index.tsx +9 -9
- package/src/Questions/Questions.stories.js +1 -1
- package/src/Questions/Questions.tsx +2 -2
- package/src/Questions/Step/ReviewStep.tsx +6 -6
- package/src/Questions/Step/Step.tsx +1 -1
- package/src/Questions/Step/StepArrayReview.tsx +11 -11
- package/src/Questions/Step/StepDescription.tsx +1 -1
- package/src/Questions/Step/StepForm.tsx +6 -6
- package/src/Questions/Step/StepTitle.tsx +16 -12
- package/src/Questions/Step/getAddMoreFields.tsx +1 -1
- package/src/Questions/__snapshots__/index.spec.tsx.snap +9 -9
- package/src/Questions/__stories__/Default.tsx +4 -4
- package/src/Questions/index.mdx +41 -44
- package/src/Questions/index.spec.tsx +1 -1
- package/src/create-simple-form.mdx +258 -237
- package/src/index.mdx +13 -6
- package/src/inputs/AutoComplete/__stories__/Default.tsx +3 -3
- package/src/inputs/AutoComplete/index.tsx +4 -4
- package/src/inputs/Checkboxes/Checkboxes.stories.js +1 -1
- package/src/inputs/Checkboxes/__stories__/Conditional.tsx +2 -2
- package/src/inputs/Checkboxes/__stories__/Default.tsx +1 -1
- package/src/inputs/Checkboxes/__stories__/WithDivider.tsx +2 -2
- package/src/inputs/Checkboxes/index.tsx +4 -4
- package/src/inputs/DateInput/DateInput.stories.js +1 -1
- package/src/inputs/DateInput/__stories__/Default.tsx +1 -1
- package/src/inputs/DateInput/index.tsx +2 -2
- package/src/inputs/FileInput/FileInput.stories.js +1 -1
- package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
- package/src/inputs/FileInput/index.tsx +5 -5
- package/src/inputs/Input/__stories__/AFM.tsx +1 -1
- package/src/inputs/Input/__stories__/Boolean.tsx +1 -1
- package/src/inputs/Input/__stories__/Default.tsx +1 -1
- package/src/inputs/Input/__stories__/IBAN.tsx +1 -1
- package/src/inputs/Input/__stories__/Integer.tsx +1 -1
- package/src/inputs/Input/__stories__/MobilePhone.tsx +1 -1
- package/src/inputs/Input/__stories__/PhoneNumber.tsx +1 -1
- package/src/inputs/Input/__stories__/PostalCode.tsx +1 -1
- package/src/inputs/Input/__stories__/TextWithCharacterLimit.tsx +1 -1
- package/src/inputs/Input/index.tsx +3 -3
- package/src/inputs/Label/Label.stories.js +1 -1
- package/src/inputs/Label/__stories__/Default.tsx +1 -1
- package/src/inputs/Label/index.tsx +4 -4
- package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
- package/src/inputs/OtpInput/index.tsx +7 -3
- package/src/inputs/Radio/Radio.stories.js +1 -2
- package/src/inputs/Radio/__stories__/Conditional.tsx +3 -3
- package/src/inputs/Radio/__stories__/Default.tsx +1 -1
- package/src/inputs/Radio/__stories__/WithDivider.tsx +2 -2
- package/src/inputs/Radio/index.tsx +6 -6
- package/src/inputs/Select/Select.stories.js +1 -1
- package/src/inputs/Select/__stories__/Default.tsx +1 -1
- package/src/inputs/Select/index.tsx +2 -2
- package/src/installation.mdx +12 -16
- package/src/types.tsx +4 -2
- package/src/utils.ts +1 -1
- package/src/validators/index.ts +10 -10
- package/src/validators/utils/file.ts +1 -1
- package/src/validators/utils/phone.ts +1 -1
- package/src/validators/utils/postal_code.ts +1 -1
- package/types.d.ts +4 -2
- package/validators/index.d.ts +3 -3
- package/validators/index.js +4 -4
- package/validators/utils/file.d.ts +1 -1
- package/validators/utils/phone.d.ts +1 -1
- package/validators/utils/postal_code.d.ts +1 -1
|
@@ -4,21 +4,23 @@ title: Create a simple Digigov Form
|
|
|
4
4
|
sidebar_label: Creating simple forms
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
import LeadText from
|
|
7
|
+
import LeadText from '@site/src/components/LeadText';
|
|
8
8
|
|
|
9
|
-
<LeadText>
|
|
10
|
-
|
|
9
|
+
<LeadText>
|
|
10
|
+
This guide walks through building a simple form page, complete with validation
|
|
11
|
+
and data serialisation.
|
|
12
|
+
</LeadText>
|
|
11
13
|
|
|
12
14
|
## What we are building
|
|
13
15
|
|
|
14
16
|
Before we start diving into more advanced usecases, let's first create a form
|
|
15
17
|
asking users for their personal information.
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
- First name
|
|
20
|
+
- Last name
|
|
21
|
+
- AFM (Greek tax number)
|
|
22
|
+
- Telephone number
|
|
23
|
+
- Marital status
|
|
22
24
|
|
|
23
25
|
As you can see, this form is pretty basic. But even for a basic form like this
|
|
24
26
|
we want to implement features that will help our users submit their data. We
|
|
@@ -39,13 +41,15 @@ primitive elements.
|
|
|
39
41
|
import React from 'react';
|
|
40
42
|
|
|
41
43
|
export default function SimpleForm() {
|
|
42
|
-
return
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
return (
|
|
45
|
+
<form>
|
|
46
|
+
<label>
|
|
47
|
+
Name:
|
|
48
|
+
<input type="text" name="name" />
|
|
49
|
+
</label>
|
|
50
|
+
<input type="submit" value="Submit" />
|
|
51
|
+
</form>
|
|
52
|
+
);
|
|
49
53
|
}
|
|
50
54
|
```
|
|
51
55
|
|
|
@@ -65,9 +69,7 @@ import Form from '@digigov/form';
|
|
|
65
69
|
|
|
66
70
|
export default function SimpleForm() {
|
|
67
71
|
// highlight-start
|
|
68
|
-
return <Form>
|
|
69
|
-
{/* this is where the fields are going to be placed */}
|
|
70
|
-
</Form>
|
|
72
|
+
return <Form>{/* this is where the fields are going to be placed */}</Form>;
|
|
71
73
|
// highlight-end
|
|
72
74
|
}
|
|
73
75
|
```
|
|
@@ -82,11 +84,11 @@ Let's go ahead and import the `Field` component and use it to render an input
|
|
|
82
84
|
field and a label. This component creates and manages any necessary React
|
|
83
85
|
components transparently. All you need to do is describe a few React props.
|
|
84
86
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
- `key`
|
|
88
|
+
- `name`
|
|
89
|
+
- `type`
|
|
90
|
+
- `label`
|
|
91
|
+
- `required`
|
|
90
92
|
|
|
91
93
|
These props can be then passed down the `Field` component which will be rendered
|
|
92
94
|
by `FormBuilder`.
|
|
@@ -100,21 +102,23 @@ import React from 'react';
|
|
|
100
102
|
import Form, { Field } from '@digigov/form';
|
|
101
103
|
|
|
102
104
|
export default function SimpleForm() {
|
|
103
|
-
return
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
return (
|
|
106
|
+
<Form>
|
|
107
|
+
// highlight-start
|
|
108
|
+
<Field
|
|
109
|
+
key="firstName"
|
|
110
|
+
name="firstName"
|
|
111
|
+
label={{ primary: 'First name' }}
|
|
112
|
+
type="string"
|
|
113
|
+
required
|
|
114
|
+
/>
|
|
115
|
+
// highlight-end
|
|
116
|
+
</Form>
|
|
117
|
+
);
|
|
114
118
|
}
|
|
115
119
|
```
|
|
116
120
|
|
|
117
|
-
Hooray! 🎉
|
|
121
|
+
Hooray! 🎉
|
|
118
122
|
|
|
119
123
|
It looks like the first two fields of our awesome form are working as
|
|
120
124
|
expected. They are pretty basic, string inputs, accepting data input but they
|
|
@@ -125,22 +129,24 @@ import React from 'react';
|
|
|
125
129
|
import Form, { Field } from '@digigov/form';
|
|
126
130
|
|
|
127
131
|
export default function SimpleForm() {
|
|
128
|
-
return
|
|
129
|
-
<
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
132
|
+
return (
|
|
133
|
+
<Form>
|
|
134
|
+
<Field
|
|
135
|
+
key="firstName"
|
|
136
|
+
name="firstName"
|
|
137
|
+
label={{ primary: 'First name' }}
|
|
138
|
+
type="string"
|
|
139
|
+
required
|
|
140
|
+
/>
|
|
141
|
+
<Field
|
|
142
|
+
key="lastName"
|
|
143
|
+
name="lastName"
|
|
144
|
+
label={{ primary: 'Last name' }}
|
|
145
|
+
type="string"
|
|
146
|
+
required
|
|
147
|
+
/>
|
|
148
|
+
</Form>
|
|
149
|
+
);
|
|
144
150
|
}
|
|
145
151
|
```
|
|
146
152
|
|
|
@@ -150,7 +156,7 @@ Before we proceed with adding the rest of the fields, we should first make sure
|
|
|
150
156
|
that the form is working, validating and submitting data.
|
|
151
157
|
|
|
152
158
|
Let's modify the previous example and use a `@digigov/ui/form/Button` to submit
|
|
153
|
-
data. First we should import the button component
|
|
159
|
+
data. First we should import the button component and use it right at the
|
|
154
160
|
bottom of our form.
|
|
155
161
|
|
|
156
162
|
It is important to note that you should make sure the Button has a
|
|
@@ -162,28 +168,30 @@ enter key) or using any other tools eg. screen readers.
|
|
|
162
168
|
import React from 'react';
|
|
163
169
|
import Form, { Field } from '@digigov/form';
|
|
164
170
|
// highlight-next-line
|
|
165
|
-
import Button from '@digigov/ui/
|
|
171
|
+
import Button from '@digigov/ui/form/Button';
|
|
166
172
|
|
|
167
173
|
export default function SimpleForm() {
|
|
168
|
-
return
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
174
|
+
return (
|
|
175
|
+
<Form>
|
|
176
|
+
{/* this is where the fields are going to be placed */}
|
|
177
|
+
<Field
|
|
178
|
+
key="firstName"
|
|
179
|
+
name="firstName"
|
|
180
|
+
label={{ primary: 'First name' }}
|
|
181
|
+
type="string"
|
|
182
|
+
required
|
|
183
|
+
/>
|
|
184
|
+
<Field
|
|
185
|
+
key="lastName"
|
|
186
|
+
name="lastName"
|
|
187
|
+
label={{ primary: 'Last name' }}
|
|
188
|
+
type="string"
|
|
189
|
+
required
|
|
190
|
+
/>
|
|
191
|
+
// highlight-next-line
|
|
192
|
+
<Button type="submit">Continue</Button>
|
|
193
|
+
</Form>
|
|
194
|
+
);
|
|
187
195
|
}
|
|
188
196
|
```
|
|
189
197
|
|
|
@@ -198,33 +206,35 @@ affects the submit behaviour.
|
|
|
198
206
|
```jsx live
|
|
199
207
|
import React from 'react';
|
|
200
208
|
import Form, { Field } from '@digigov/form';
|
|
201
|
-
import Button from '@digigov/ui/
|
|
209
|
+
import Button from '@digigov/ui/form/Button';
|
|
202
210
|
|
|
203
211
|
export default function SimpleForm() {
|
|
204
|
-
return
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
212
|
+
return (
|
|
213
|
+
<Form>
|
|
214
|
+
{/* this is where the fields are going to be placed */}
|
|
215
|
+
<Field
|
|
216
|
+
key="firstName"
|
|
217
|
+
name="firstName"
|
|
218
|
+
label={{ primary: 'First name' }}
|
|
219
|
+
type="string"
|
|
220
|
+
required
|
|
221
|
+
/>
|
|
222
|
+
<Field
|
|
223
|
+
key="lastName"
|
|
224
|
+
name="lastName"
|
|
225
|
+
label={{ primary: 'Last name' }}
|
|
226
|
+
type="string"
|
|
227
|
+
required
|
|
228
|
+
/>
|
|
229
|
+
<Button type="submit">Continue</Button>
|
|
230
|
+
</Form>
|
|
231
|
+
);
|
|
222
232
|
}
|
|
223
233
|
```
|
|
224
234
|
|
|
225
235
|
Straightaway, the form is actually doing something and it is validating our
|
|
226
236
|
inputs with almost zero coding needed.
|
|
227
|
-
|
|
237
|
+
|
|
228
238
|
That's good. But we have yet to gather data in our code when users submit the form.
|
|
229
239
|
|
|
230
240
|
Note. We should note that behind the scenes the Digigov Form inherits a prop (from [React Hook Form](https://react-hook-form.com/api/useform/)) called `shouldFocusError`
|
|
@@ -252,43 +262,47 @@ information.
|
|
|
252
262
|
// highlight-next-line
|
|
253
263
|
import React, { useState } from 'react';
|
|
254
264
|
import Form, { Field } from '@digigov/form';
|
|
255
|
-
import Button from '@digigov/ui/
|
|
265
|
+
import Button from '@digigov/ui/form/Button';
|
|
256
266
|
|
|
257
267
|
export default function SimpleForm() {
|
|
258
268
|
// highlight-start
|
|
259
|
-
const [submittedData, setSubmittedData] = useState({})
|
|
269
|
+
const [submittedData, setSubmittedData] = useState({});
|
|
260
270
|
const handleSubmit = (data) => {
|
|
261
271
|
setSubmittedData(data);
|
|
262
|
-
}
|
|
263
|
-
return
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
272
|
+
};
|
|
273
|
+
return (
|
|
274
|
+
<>
|
|
275
|
+
<Form onSubmit={handleSubmit}>
|
|
276
|
+
// highlight-end
|
|
277
|
+
{/* this is where the fields are going to be placed */}
|
|
278
|
+
<Field
|
|
279
|
+
key="firstName"
|
|
280
|
+
name="firstName"
|
|
281
|
+
label={{ primary: 'First name' }}
|
|
282
|
+
type="string"
|
|
283
|
+
required
|
|
284
|
+
/>
|
|
285
|
+
<Field
|
|
286
|
+
key="lastName"
|
|
287
|
+
name="lastName"
|
|
288
|
+
label={{ primary: 'Last name' }}
|
|
289
|
+
type="string"
|
|
290
|
+
required
|
|
291
|
+
/>
|
|
292
|
+
<Button type="submit">Continue</Button>
|
|
293
|
+
</Form>
|
|
294
|
+
// highlight-start
|
|
295
|
+
{
|
|
296
|
+
<>
|
|
297
|
+
You submitted the following values
|
|
298
|
+
<pre>
|
|
299
|
+
<code>{JSON.stringify(submittedData)}</code>
|
|
300
|
+
</pre>
|
|
301
|
+
</>
|
|
302
|
+
}
|
|
303
|
+
// highlight-end
|
|
304
|
+
</>
|
|
305
|
+
);
|
|
292
306
|
}
|
|
293
307
|
```
|
|
294
308
|
|
|
@@ -302,40 +316,44 @@ button or press enter and see what happens.
|
|
|
302
316
|
```jsx live
|
|
303
317
|
import React, { useState } from 'react';
|
|
304
318
|
import Form, { Field } from '@digigov/form';
|
|
305
|
-
import Button from '@digigov/ui/
|
|
319
|
+
import Button from '@digigov/ui/form/Button';
|
|
306
320
|
import Paragraph from '@digigov/ui/typography/Paragraph';
|
|
307
321
|
|
|
308
322
|
export default function SimpleForm() {
|
|
309
|
-
const [submittedData, setSubmittedData] = useState({})
|
|
323
|
+
const [submittedData, setSubmittedData] = useState({});
|
|
310
324
|
const handleSubmit = (data) => {
|
|
311
325
|
setSubmittedData(data);
|
|
312
|
-
}
|
|
313
|
-
return
|
|
314
|
-
|
|
315
|
-
{
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
326
|
+
};
|
|
327
|
+
return (
|
|
328
|
+
<>
|
|
329
|
+
<Form onSubmit={handleSubmit}>
|
|
330
|
+
{/* this is where the fields are going to be placed */}
|
|
331
|
+
<Field
|
|
332
|
+
key="firstName"
|
|
333
|
+
name="firstName"
|
|
334
|
+
label={{ primary: 'First name' }}
|
|
335
|
+
type="string"
|
|
336
|
+
required
|
|
337
|
+
/>
|
|
338
|
+
<Field
|
|
339
|
+
key="lastName"
|
|
340
|
+
name="lastName"
|
|
341
|
+
label={{ primary: 'Last name' }}
|
|
342
|
+
type="string"
|
|
343
|
+
required
|
|
344
|
+
/>
|
|
345
|
+
<Button type="submit">Continue</Button>
|
|
346
|
+
</Form>
|
|
347
|
+
{
|
|
348
|
+
<Paragraph>
|
|
349
|
+
You have submitted the following values
|
|
350
|
+
<pre>
|
|
351
|
+
<code>{JSON.stringify(submittedData)}</code>
|
|
352
|
+
</pre>
|
|
353
|
+
</Paragraph>
|
|
354
|
+
}
|
|
355
|
+
</>
|
|
356
|
+
);
|
|
339
357
|
}
|
|
340
358
|
```
|
|
341
359
|
|
|
@@ -370,8 +388,8 @@ the format of this tax number
|
|
|
370
388
|
name="taxNumber"
|
|
371
389
|
type="afm"
|
|
372
390
|
label={{
|
|
373
|
-
primary:
|
|
374
|
-
secondary:
|
|
391
|
+
primary: 'Tax number',
|
|
392
|
+
secondary: 'Tax number is your AFM number, given to you by AADE',
|
|
375
393
|
}}
|
|
376
394
|
required
|
|
377
395
|
/>
|
|
@@ -386,8 +404,8 @@ A similar field can be used for the phone number. You can use the
|
|
|
386
404
|
name="phoneNumber"
|
|
387
405
|
type="phone_number"
|
|
388
406
|
label={{
|
|
389
|
-
primary:
|
|
390
|
-
secondary:
|
|
407
|
+
primary: 'Phone number',
|
|
408
|
+
secondary: 'You can enter any landline phone number.',
|
|
391
409
|
}}
|
|
392
410
|
required
|
|
393
411
|
/>
|
|
@@ -398,29 +416,28 @@ A similar field can be used for the phone number. You can use the
|
|
|
398
416
|
Last but not least, we should create a single choice field, which will be
|
|
399
417
|
rendered as a radio group of answers.
|
|
400
418
|
|
|
401
|
-
|
|
402
419
|
```jsx
|
|
403
420
|
<Field
|
|
404
421
|
key="maritalStatus"
|
|
405
422
|
name="maritalStatus"
|
|
406
423
|
type="choice:single"
|
|
407
|
-
label={{primary:
|
|
424
|
+
label={{ primary: 'Marital status' }}
|
|
408
425
|
required
|
|
409
426
|
extra={{
|
|
410
427
|
options: [
|
|
411
428
|
{
|
|
412
|
-
label: {primary:
|
|
429
|
+
label: { primary: 'Married' },
|
|
413
430
|
value: 'married',
|
|
414
431
|
},
|
|
415
432
|
{
|
|
416
|
-
label: {primary:
|
|
433
|
+
label: { primary: 'Cohabitation agreement' },
|
|
417
434
|
value: 'cohabitation',
|
|
418
435
|
},
|
|
419
436
|
{
|
|
420
|
-
label: {primary:
|
|
437
|
+
label: { primary: 'Prefer not to answer' },
|
|
421
438
|
value: 'wontanswer',
|
|
422
|
-
}
|
|
423
|
-
]
|
|
439
|
+
},
|
|
440
|
+
],
|
|
424
441
|
}}
|
|
425
442
|
/>
|
|
426
443
|
```
|
|
@@ -435,84 +452,88 @@ Feel free to fill the form in the example and submit it.
|
|
|
435
452
|
```jsx live
|
|
436
453
|
import React, { useState } from 'react';
|
|
437
454
|
import Form, { Field } from '@digigov/form';
|
|
438
|
-
import Button from '@digigov/ui/
|
|
455
|
+
import Button from '@digigov/ui/form/Button';
|
|
439
456
|
import Paragraph from '@digigov/ui/typography/Paragraph';
|
|
440
457
|
|
|
441
458
|
export default function SimpleForm() {
|
|
442
|
-
const [submittedData, setSubmittedData] = useState({})
|
|
459
|
+
const [submittedData, setSubmittedData] = useState({});
|
|
443
460
|
const handleSubmit = (data) => {
|
|
444
461
|
setSubmittedData(data);
|
|
445
|
-
}
|
|
446
|
-
return
|
|
447
|
-
|
|
448
|
-
{
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
462
|
+
};
|
|
463
|
+
return (
|
|
464
|
+
<>
|
|
465
|
+
<Form onSubmit={handleSubmit}>
|
|
466
|
+
{/* this is where the fields are going to be placed */}
|
|
467
|
+
<Field
|
|
468
|
+
key="firstName"
|
|
469
|
+
name="firstName"
|
|
470
|
+
label={{ primary: 'First name' }}
|
|
471
|
+
type="string"
|
|
472
|
+
required
|
|
473
|
+
/>
|
|
474
|
+
<Field
|
|
475
|
+
key="lastName"
|
|
476
|
+
name="lastName"
|
|
477
|
+
label={{ primary: 'Last name' }}
|
|
478
|
+
type="string"
|
|
479
|
+
required
|
|
480
|
+
/>
|
|
481
|
+
<Field
|
|
482
|
+
key="taxNumber"
|
|
483
|
+
name="taxNumber"
|
|
484
|
+
type="afm"
|
|
485
|
+
label={{
|
|
486
|
+
primary: 'Tax number',
|
|
487
|
+
secondary: 'Tax number is your AFM number, given to you by AADE',
|
|
488
|
+
}}
|
|
489
|
+
required
|
|
490
|
+
/>
|
|
491
|
+
<Field
|
|
492
|
+
key="phoneNumber"
|
|
493
|
+
name="phoneNumber"
|
|
494
|
+
type="phone_number"
|
|
495
|
+
label={{
|
|
496
|
+
primary: 'Phone number',
|
|
497
|
+
secondary: 'You can enter any landline phone number.',
|
|
498
|
+
}}
|
|
499
|
+
required
|
|
500
|
+
/>
|
|
501
|
+
<Field
|
|
502
|
+
key="maritalStatus"
|
|
503
|
+
name="maritalStatus"
|
|
504
|
+
type="choice:single"
|
|
505
|
+
label={{ primary: 'Marital status' }}
|
|
506
|
+
required
|
|
507
|
+
extra={{
|
|
508
|
+
options: [
|
|
509
|
+
{
|
|
510
|
+
label: { primary: 'Married' },
|
|
511
|
+
value: 'married',
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
label: { primary: 'Cohabitation agreement' },
|
|
515
|
+
value: 'cohabitation',
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
label: { primary: 'Prefer not to answer' },
|
|
519
|
+
value: 'wontanswer',
|
|
520
|
+
},
|
|
521
|
+
],
|
|
522
|
+
}}
|
|
523
|
+
/>
|
|
524
|
+
<Button type="submit">Continue</Button>
|
|
525
|
+
</Form>
|
|
526
|
+
{
|
|
527
|
+
<Paragraph>
|
|
528
|
+
You have submitted the following values
|
|
529
|
+
<pre>
|
|
530
|
+
<code>{JSON.stringify(submittedData)}</code>
|
|
531
|
+
</pre>
|
|
532
|
+
</Paragraph>
|
|
533
|
+
}
|
|
534
|
+
</>
|
|
535
|
+
);
|
|
515
536
|
}
|
|
516
537
|
```
|
|
517
538
|
|
|
518
|
-
Perfect! We now have a finished form, complete with field validation.
|
|
539
|
+
Perfect! We now have a finished form, complete with field validation.
|