@digigov/form 2.0.0-6e3977bc → 2.0.0-834daea4
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/FieldBaseContainer/index.js +3 -3
- package/Field/FieldBaseContainer.js.map +2 -2
- package/Field/types.d.ts +1 -0
- package/FieldArray/index.js +4 -4
- package/FieldArray/index.js.map +2 -2
- package/FieldObject/index.js +2 -2
- package/FieldObject/index.js.map +2 -2
- package/Fieldset/index.d.ts +1 -1
- package/Fieldset/index.js +5 -5
- package/Fieldset/index.js.map +2 -2
- package/Fieldset/types.d.ts +2 -2
- package/FormBuilder/index.js +3 -3
- package/FormBuilder/index.js.map +2 -2
- package/MultiplicityField/add-objects/index.js +4 -4
- package/MultiplicityField/add-objects.js.map +2 -2
- package/MultiplicityField/index.js +12 -10
- package/MultiplicityField/index.js.map +2 -2
- package/Questions/Step/StepTitle/index.js +4 -3
- package/Questions/Step/StepTitle.d.ts +1 -1
- package/Questions/Step/StepTitle.js.map +2 -2
- package/cjs/Field/FieldBaseContainer/index.js +3 -3
- package/cjs/Field/FieldBaseContainer.js.map +3 -3
- package/cjs/Field/types.js.map +1 -1
- package/cjs/FieldArray/index.js +6 -6
- package/cjs/FieldArray/index.js.map +3 -3
- package/cjs/FieldObject/index.js +3 -3
- package/cjs/FieldObject/index.js.map +3 -3
- package/cjs/Fieldset/index.js +10 -10
- package/cjs/Fieldset/index.js.map +3 -3
- package/cjs/Fieldset/types.js.map +1 -1
- package/cjs/FormBuilder/index.js +5 -5
- package/cjs/FormBuilder/index.js.map +3 -3
- package/cjs/MultiplicityField/add-objects/index.js +8 -8
- package/cjs/MultiplicityField/add-objects.js.map +3 -3
- package/cjs/MultiplicityField/index.js +11 -14
- package/cjs/MultiplicityField/index.js.map +3 -3
- package/cjs/Questions/Step/StepTitle/index.js +5 -5
- package/cjs/Questions/Step/StepTitle.js.map +3 -3
- package/cjs/inputs/AutoCompleteInput/index.js +4 -4
- package/cjs/inputs/AutoCompleteInput/index.js.map +3 -3
- package/cjs/inputs/Checkboxes/index.js +6 -8
- package/cjs/inputs/Checkboxes/index.js.map +3 -3
- package/cjs/inputs/DateInput/index.js +3 -4
- package/cjs/inputs/DateInput/index.js.map +3 -3
- package/cjs/inputs/FileInput/index.js +7 -8
- package/cjs/inputs/FileInput/index.js.map +3 -3
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +2 -1
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension.js.map +2 -2
- package/cjs/inputs/ImageInput/index.js +7 -8
- package/cjs/inputs/ImageInput/index.js.map +3 -3
- package/cjs/inputs/Input/index.js +4 -4
- package/cjs/inputs/Input/index.js.map +2 -2
- package/cjs/inputs/Label/index.js +3 -3
- package/cjs/inputs/Label/index.js.map +3 -3
- package/cjs/inputs/Radio/index.js +11 -13
- package/cjs/inputs/Radio/index.js.map +3 -3
- package/cjs/inputs/Select/index.js +3 -4
- package/cjs/inputs/Select/index.js.map +3 -3
- package/cjs/lazy/index.js +4 -0
- package/cjs/lazy.js.map +2 -2
- package/cjs/registry/index.js +2 -0
- package/cjs/registry.js.map +2 -2
- package/cjs/validators/index.js +6 -65
- package/cjs/validators/index.js.map +3 -3
- package/cjs/validators/utils/date/index.js +138 -0
- package/cjs/validators/utils/date.js.map +7 -0
- package/cjs/validators/utils/index.js +3 -1
- package/cjs/validators/utils/index.js.map +2 -2
- package/index.js +1 -1
- package/inputs/AutoCompleteInput/index.js +6 -4
- package/inputs/AutoCompleteInput/index.js.map +2 -2
- package/inputs/Checkboxes/index.js +7 -5
- package/inputs/Checkboxes/index.js.map +2 -2
- package/inputs/DateInput/index.js +5 -3
- package/inputs/DateInput/index.js.map +2 -2
- package/inputs/FileInput/index.js +5 -6
- package/inputs/FileInput/index.js.map +2 -2
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +2 -1
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.js.map +2 -2
- package/inputs/ImageInput/index.js +6 -7
- package/inputs/ImageInput/index.js.map +2 -2
- package/inputs/Input/index.js +4 -4
- package/inputs/Input/index.js.map +2 -2
- package/inputs/Label/index.js +2 -2
- package/inputs/Label/index.js.map +2 -2
- package/inputs/Radio/index.js +7 -5
- package/inputs/Radio/index.js.map +2 -2
- package/inputs/Select/index.js +1 -2
- package/inputs/Select/index.js.map +2 -2
- package/lazy/index.js +4 -0
- package/lazy.d.ts +4 -0
- package/lazy.js.map +2 -2
- package/package.json +4 -4
- package/registry/index.js +2 -0
- package/registry.d.ts +1 -0
- package/registry.js.map +2 -2
- package/src/Field/FieldBaseContainer.tsx +4 -2
- package/src/Field/types.tsx +20 -19
- package/src/FieldArray/index.tsx +9 -8
- package/src/FieldObject/index.tsx +2 -2
- package/src/Fieldset/index.tsx +5 -5
- package/src/Fieldset/types.tsx +2 -2
- package/src/FormBuilder/{FormBuilder.mdx → doc.mdx} +20 -33
- package/src/FormBuilder/index.tsx +3 -3
- package/src/MultiplicityField/add-objects.tsx +5 -6
- package/src/MultiplicityField/{MultiplicityField.mdx → doc.mdx} +12 -16
- package/src/MultiplicityField/index.tsx +13 -12
- package/src/Questions/Step/StepTitle.tsx +4 -3
- package/src/Questions/__snapshots__/index.spec.tsx.snap +17 -13
- package/src/Questions/{index.mdx → doc.mdx} +9 -12
- package/src/create-simple-form.mdx +2 -6
- package/src/{index.mdx → doc.mdx} +4 -8
- package/src/inputs/AutoCompleteInput/{index.mdx → doc.mdx} +2 -13
- package/src/inputs/AutoCompleteInput/index.tsx +31 -26
- package/src/inputs/Checkboxes/{index.mdx → doc.mdx} +5 -15
- package/src/inputs/Checkboxes/index.tsx +29 -27
- package/src/inputs/DateInput/{index.mdx → doc.mdx} +1 -8
- package/src/inputs/DateInput/index.tsx +5 -3
- package/src/inputs/FileInput/{index.mdx → doc.mdx} +1 -5
- package/src/inputs/FileInput/index.tsx +5 -6
- package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +2 -0
- package/src/inputs/ImageInput/doc.mdx +23 -0
- package/src/inputs/ImageInput/index.tsx +9 -11
- package/src/inputs/Input/doc.mdx +56 -0
- package/src/inputs/Input/index.tsx +19 -11
- package/src/inputs/Label/doc.mdx +14 -0
- package/src/inputs/Label/index.tsx +2 -3
- package/src/inputs/OtpInput/{index.mdx → doc.mdx} +1 -8
- package/src/inputs/Radio/{index.mdx → doc.mdx} +5 -15
- package/src/inputs/Radio/index.tsx +57 -55
- package/src/inputs/Select/{index.mdx → doc.mdx} +1 -5
- package/src/inputs/Select/index.tsx +1 -2
- package/src/installation.mdx +2 -5
- package/src/lazy.js +4 -0
- package/src/registry.js +2 -0
- package/src/validators/index.ts +10 -70
- package/src/validators/utils/date.ts +107 -0
- package/src/validators/utils/index.ts +1 -0
- package/validators/index.js +10 -66
- package/validators/index.js.map +2 -2
- package/validators/utils/date/index.js +103 -0
- package/validators/utils/date/package.json +6 -0
- package/validators/utils/date.d.ts +9 -0
- package/validators/utils/date.js.map +7 -0
- package/validators/utils/index.d.ts +1 -0
- package/validators/utils/index.js +1 -0
- package/validators/utils/index.js.map +2 -2
- package/src/inputs/ImageInput/index.mdx +0 -19
- package/src/inputs/Input/index.mdx +0 -95
- package/src/inputs/Label/index.mdx +0 -0
- /package/src/Field/{index.mdx → doc.mdx} +0 -0
|
@@ -3,13 +3,9 @@ id: ask-users-recursive
|
|
|
3
3
|
title: Ask users for recursive data
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Multiplicity & FieldArray fields allow users to input data described by a
|
|
10
|
-
particular schema for an arbitrary number of times until they are done. It can
|
|
11
|
-
be used to input a fixed, a minimum, and a maximum length of instances.
|
|
12
|
-
</LeadText>
|
|
6
|
+
Multiplicity & FieldArray fields allow users to input data described by a
|
|
7
|
+
particular schema for an arbitrary number of times until they are done. It can
|
|
8
|
+
be used to input a fixed, a minimum, and a maximum length of instances.
|
|
13
9
|
|
|
14
10
|
## What we are trying to achieve
|
|
15
11
|
|
|
@@ -108,7 +104,7 @@ This field is the most complex component we currently offer, and it uses the
|
|
|
108
104
|
react-hook-form under the hood. First, let's take a look at what it looks like, and then we can
|
|
109
105
|
break down its functionality and how you can use it.
|
|
110
106
|
|
|
111
|
-
```jsx
|
|
107
|
+
```jsx
|
|
112
108
|
import React from 'react';
|
|
113
109
|
import Form, { Field } from '@digigov/form';
|
|
114
110
|
import Button from '@digigov/ui/form/Button';
|
|
@@ -209,7 +205,7 @@ are asking users for information about their vehicles, we can also fill in the `
|
|
|
209
205
|
`label.primary`, as well as the `type` and `required`
|
|
210
206
|
props.
|
|
211
207
|
|
|
212
|
-
```jsx
|
|
208
|
+
```jsx pure
|
|
213
209
|
<Field
|
|
214
210
|
key="vehicles"
|
|
215
211
|
name="vehicles"
|
|
@@ -232,7 +228,7 @@ inner form, respectively.
|
|
|
232
228
|
Inside the `of` key you can add an `extra` key that will then contain a `fields`
|
|
233
229
|
key describing the field props for all inputs needed.
|
|
234
230
|
|
|
235
|
-
```js
|
|
231
|
+
```js pure
|
|
236
232
|
// this will be used as value for the `extra` prop
|
|
237
233
|
{
|
|
238
234
|
of: {
|
|
@@ -290,7 +286,7 @@ As a result, if you learn how to use one, you can easily use the other, and
|
|
|
290
286
|
naturally, you can also change their behaviour by changing a single prop in your
|
|
291
287
|
React code.
|
|
292
288
|
|
|
293
|
-
```jsx
|
|
289
|
+
```jsx pure
|
|
294
290
|
<Field
|
|
295
291
|
key="vehicles"
|
|
296
292
|
name="vehicles"
|
|
@@ -305,7 +301,7 @@ React code.
|
|
|
305
301
|
The end result looks very different from Multiplicity at first glance, but you
|
|
306
302
|
can achieve the same results with both of them.
|
|
307
303
|
|
|
308
|
-
```jsx
|
|
304
|
+
```jsx
|
|
309
305
|
import React from 'react';
|
|
310
306
|
import Form, { Field } from '@digigov/form';
|
|
311
307
|
import Button from '@digigov/ui/form/Button';
|
|
@@ -396,7 +392,7 @@ should expect to need some length validation sooner than later.
|
|
|
396
392
|
You can easily validate the exact length of the items added to the multipliticy
|
|
397
393
|
array, simply by using the `extra.length` prop.
|
|
398
394
|
|
|
399
|
-
```jsx
|
|
395
|
+
```jsx pure
|
|
400
396
|
<Field
|
|
401
397
|
extra={{
|
|
402
398
|
length: 2,
|
|
@@ -409,7 +405,7 @@ array, simply by using the `extra.length` prop.
|
|
|
409
405
|
The example below will validate this and show all the error messages necessary
|
|
410
406
|
to make sure that the users understand what is going wrong with the process.
|
|
411
407
|
|
|
412
|
-
```jsx
|
|
408
|
+
```jsx
|
|
413
409
|
import React from 'react';
|
|
414
410
|
import Form, { Field } from '@digigov/form';
|
|
415
411
|
import Button from '@digigov/ui/form/Button';
|
|
@@ -497,7 +493,7 @@ Do not mix and match the exact `length` validation with the `min` or `max`.
|
|
|
497
493
|
|
|
498
494
|
:::
|
|
499
495
|
|
|
500
|
-
```jsx
|
|
496
|
+
```jsx pure
|
|
501
497
|
<Field
|
|
502
498
|
extra={{
|
|
503
499
|
min: 2,
|
|
@@ -511,7 +507,7 @@ Do not mix and match the exact `length` validation with the `min` or `max`.
|
|
|
511
507
|
The example below will validate this and show all the error messages necessary
|
|
512
508
|
to make sure that the users understand what is going wrong with the process.
|
|
513
509
|
|
|
514
|
-
```jsx
|
|
510
|
+
```jsx
|
|
515
511
|
import React from 'react';
|
|
516
512
|
import Form, { Field } from '@digigov/form';
|
|
517
513
|
import Button from '@digigov/ui/form/Button';
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import { useFieldArray, UseFormReturn } from 'react-hook-form';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import AddObjects from '@digigov/form/MultiplicityField/add-objects';
|
|
3
|
+
import { FieldBaseContainer } from '@digigov/form/Field/FieldBaseContainer';
|
|
4
|
+
import { FieldObject } from '@digigov/form/FieldObject';
|
|
5
|
+
import { AddObjects } from '@digigov/form/MultiplicityField/add-objects';
|
|
7
6
|
import {
|
|
8
7
|
MultiplicityProps,
|
|
9
8
|
StashedObject,
|
|
10
9
|
} from '@digigov/form/MultiplicityField/types';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
import {
|
|
11
|
+
Card,
|
|
12
|
+
CardHeading,
|
|
13
|
+
CardContent,
|
|
14
|
+
CardAction,
|
|
15
|
+
} from '@digigov/ui/content/Card';
|
|
16
|
+
import { Button } from '@digigov/ui/form/Button';
|
|
17
|
+
import { Heading } from '@digigov/ui/typography/Heading';
|
|
17
18
|
|
|
18
19
|
// epeidh einai forwardRef to ref mas to dinei xwrista apo ta props
|
|
19
20
|
export const Multiplicity: React.FC<MultiplicityProps> = ({
|
|
@@ -48,7 +49,7 @@ export const Multiplicity: React.FC<MultiplicityProps> = ({
|
|
|
48
49
|
setStashedObjects(newStashedObjects);
|
|
49
50
|
};
|
|
50
51
|
return (
|
|
51
|
-
<
|
|
52
|
+
<FieldBaseContainer
|
|
52
53
|
label={label}
|
|
53
54
|
layout={layout}
|
|
54
55
|
error={
|
|
@@ -99,7 +100,7 @@ export const Multiplicity: React.FC<MultiplicityProps> = ({
|
|
|
99
100
|
clearErrors={clearErrors}
|
|
100
101
|
Field={Field}
|
|
101
102
|
/>
|
|
102
|
-
</
|
|
103
|
+
</FieldBaseContainer>
|
|
103
104
|
);
|
|
104
105
|
};
|
|
105
106
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
2
|
import { StepContext } from '@digigov/form/Questions/Step/StepContext';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import PageTitleContainer, {
|
|
3
|
+
import {
|
|
4
|
+
PageTitleContainer,
|
|
6
5
|
PageTitleCaption,
|
|
7
6
|
} from '@digigov/ui/app/PageTitleContainer';
|
|
8
7
|
import { useTranslation } from '@digigov/ui/i18n';
|
|
9
8
|
import { BackLink } from '@digigov/ui/navigation/BackLink';
|
|
9
|
+
import { Heading, HeadingProps } from '@digigov/ui/typography/Heading';
|
|
10
|
+
import { HeadingCaption } from '@digigov/ui/typography/HeadingCaption';
|
|
10
11
|
|
|
11
12
|
export interface StepTitleInterface {
|
|
12
13
|
title?: string;
|
|
@@ -1,72 +1,76 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
3
|
exports[`renders the Questions 1`] = `
|
|
4
4
|
<body>
|
|
5
5
|
<div>
|
|
6
6
|
<a
|
|
7
|
-
class="ds-
|
|
7
|
+
class="ds-print-hidden ds-back-link"
|
|
8
8
|
tabindex="0"
|
|
9
9
|
>
|
|
10
10
|
<svg
|
|
11
11
|
aria-hidden="true"
|
|
12
|
+
as="svg"
|
|
12
13
|
class="ds-svg-icon--caret ds-svg-icon"
|
|
13
14
|
focusable="false"
|
|
14
15
|
viewBox="0 0 24 24"
|
|
15
16
|
>
|
|
16
17
|
<path
|
|
18
|
+
as="path"
|
|
19
|
+
class=""
|
|
17
20
|
d="M18,22V2L6,12L18,22z"
|
|
18
21
|
/>
|
|
19
22
|
</svg>
|
|
20
23
|
Πίσω
|
|
21
24
|
</a>
|
|
22
25
|
<div
|
|
23
|
-
class="ds-page-title"
|
|
26
|
+
class=" ds-page-title"
|
|
24
27
|
>
|
|
25
28
|
<span
|
|
26
|
-
class="ds-caption-xl"
|
|
29
|
+
class=" ds-caption-xl"
|
|
27
30
|
>
|
|
28
31
|
intro.caption
|
|
29
32
|
</span>
|
|
30
33
|
<h1
|
|
31
|
-
class="ds-heading-xl"
|
|
34
|
+
class=" ds-heading-xl"
|
|
32
35
|
>
|
|
33
36
|
intro.title
|
|
34
37
|
</h1>
|
|
35
38
|
</div>
|
|
36
39
|
<p
|
|
37
|
-
class="ds-body"
|
|
40
|
+
class=" ds-body"
|
|
38
41
|
>
|
|
39
42
|
This is the intro
|
|
40
43
|
</p>
|
|
41
44
|
<form
|
|
42
|
-
class="ds-form"
|
|
45
|
+
class=" ds-form"
|
|
43
46
|
>
|
|
44
47
|
<div
|
|
45
|
-
class="ds-field xs:ds-grid__col-span-12"
|
|
48
|
+
class=" ds-field xs:ds-grid__col-span-12"
|
|
46
49
|
>
|
|
47
50
|
<label
|
|
48
|
-
class="ds-label"
|
|
51
|
+
class=" ds-label"
|
|
49
52
|
>
|
|
50
53
|
<span
|
|
51
|
-
class="ds-
|
|
54
|
+
class=" ds-label__title ds-label__title--sm"
|
|
52
55
|
>
|
|
53
56
|
name.field.primary
|
|
54
57
|
</span>
|
|
55
58
|
<p
|
|
56
|
-
class="ds-hint"
|
|
59
|
+
class=" ds-hint"
|
|
57
60
|
>
|
|
58
61
|
name.field.secondary
|
|
59
62
|
</p>
|
|
60
63
|
<input
|
|
61
64
|
aria-required="true"
|
|
62
|
-
class="ds-input"
|
|
65
|
+
class=" ds-input"
|
|
66
|
+
data-type="string"
|
|
63
67
|
name="name"
|
|
64
68
|
type="text"
|
|
65
69
|
/>
|
|
66
70
|
</label>
|
|
67
71
|
</div>
|
|
68
72
|
<button
|
|
69
|
-
class="ds-
|
|
73
|
+
class="ds-print-hidden ds-btn ds-btn-primary"
|
|
70
74
|
type="submit"
|
|
71
75
|
>
|
|
72
76
|
Συνέχεια
|
|
@@ -14,14 +14,11 @@ import {
|
|
|
14
14
|
TableDataCell,
|
|
15
15
|
} from '@digigov/react-core';
|
|
16
16
|
|
|
17
|
-
import LeadText from '@site/src/components/LeadText';
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
out.
|
|
24
|
-
</LeadText>
|
|
18
|
+
Question pages are used to ask users meaningful questions needed by your
|
|
19
|
+
GOV.GR service, or even gather data about their persona or their application
|
|
20
|
+
status. Use step questions to make bigger forms less scary and easier to fill
|
|
21
|
+
out.
|
|
25
22
|
|
|
26
23
|
## Introduction to Question pages
|
|
27
24
|
|
|
@@ -41,7 +38,7 @@ Even if users struggle through to the end of a form and answer honestly, if it
|
|
|
41
38
|
more work than they expected, they’ll be annoyed about it. That's the exact
|
|
42
39
|
opposite of our goals of making concise, easy-to-use services.
|
|
43
40
|
|
|
44
|
-
```jsx
|
|
41
|
+
```jsx
|
|
45
42
|
import React from 'react';
|
|
46
43
|
import Questions, { Step, StepForm, StepTitle } from '@digigov/form/Questions';
|
|
47
44
|
import { Field } from '@digigov/form';
|
|
@@ -159,7 +156,7 @@ its subsequent subcomponents that you customise as needed, like the step title,
|
|
|
159
156
|
description or form. You can also add components that are not form-specific,
|
|
160
157
|
adding paragraphs or other custom components.
|
|
161
158
|
|
|
162
|
-
```jsx
|
|
159
|
+
```jsx pure
|
|
163
160
|
<Questions name="example" steps={steps} onSubmit={(data) => doSomething(data)}>
|
|
164
161
|
{/* more steps could be rendered here ... */}
|
|
165
162
|
<Step name="age">
|
|
@@ -184,7 +181,7 @@ object. The most basic properties are the following:
|
|
|
184
181
|
- `fields` - an array that describes each input field that will be rendered in
|
|
185
182
|
the `StepForm`. Each fields implements the `FieldSpec` interface as a JSON object.
|
|
186
183
|
|
|
187
|
-
```json title="step-name.json"
|
|
184
|
+
```json pure title="step-name.json"
|
|
188
185
|
{
|
|
189
186
|
"name": "name",
|
|
190
187
|
"title": "What is your name?",
|
|
@@ -209,7 +206,7 @@ basic branching between each step. The `nextStep` property will need to be a
|
|
|
209
206
|
function that will take the form state as an argument and will return the key of
|
|
210
207
|
the next `step`.
|
|
211
208
|
|
|
212
|
-
```json title="next-step.json"
|
|
209
|
+
```json pure title="next-step.json"
|
|
213
210
|
const steps = [
|
|
214
211
|
{
|
|
215
212
|
name: 'age',
|
|
@@ -263,7 +260,7 @@ For example, you may use a form to determine if citizens are adults or not, and
|
|
|
263
260
|
we want to ask users different questions according to their persona. We can use
|
|
264
261
|
a branch between the `age` step and the other two steps.
|
|
265
262
|
|
|
266
|
-
```jsx
|
|
263
|
+
```jsx
|
|
267
264
|
import React from 'react';
|
|
268
265
|
import GovGRFooter from '@digigov/ui/govgr/Footer';
|
|
269
266
|
import Header from '@digigov/ui/app/Header';
|
|
@@ -4,12 +4,8 @@ title: Create a simple Digigov Form
|
|
|
4
4
|
sidebar_label: Creating simple forms
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
<LeadText>
|
|
10
|
-
This guide walks through building a simple form page, complete with validation
|
|
11
|
-
and data serialisation.
|
|
12
|
-
</LeadText>
|
|
7
|
+
This guide walks through building a simple form page, complete with validation
|
|
8
|
+
and data serialisation.
|
|
13
9
|
|
|
14
10
|
## What we are building
|
|
15
11
|
|
|
@@ -4,14 +4,10 @@ title: Digigov Form
|
|
|
4
4
|
sidebar_label: Introduction to Digigov Form
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Reactjs. It supports flexible and multi-step forms and easy-to-use validation.
|
|
12
|
-
This page will guide you through everything you need to create accessible and
|
|
13
|
-
dynamic forms that can handle all sorts of user inputs.
|
|
14
|
-
</LeadText>
|
|
7
|
+
Digigov Form is an off-the-shelf solution for managing web forms using
|
|
8
|
+
Reactjs. It supports flexible and multi-step forms and easy-to-use validation.
|
|
9
|
+
This page will guide you through everything you need to create accessible and
|
|
10
|
+
dynamic forms that can handle all sorts of user inputs.
|
|
15
11
|
|
|
16
12
|
<img
|
|
17
13
|
src="/img/form.svg"
|
|
@@ -11,19 +11,8 @@ options as the users type and also let them select an option from the list.
|
|
|
11
11
|
|
|
12
12
|
### Default
|
|
13
13
|
|
|
14
|
-
<
|
|
15
|
-
packageName="@digigov/form"
|
|
16
|
-
component="inputs/AutoCompleteInput"
|
|
17
|
-
story="Default.tsx"
|
|
18
|
-
/>
|
|
14
|
+
<code src="@digigov/form/inputs/AutoCompleteInput/__stories__/Default.tsx" />
|
|
19
15
|
|
|
20
16
|
### Display multiple values
|
|
21
17
|
|
|
22
|
-
<
|
|
23
|
-
packageName="@digigov/form"
|
|
24
|
-
component="inputs/AutoCompleteInput"
|
|
25
|
-
story="Multiple.tsx"
|
|
26
|
-
/>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
<code src="@digigov/form/inputs/AutoCompleteInput/__stories__/Multiple.tsx" />
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
2
|
import { ControlledFieldProps } from '@digigov/form/Field/types';
|
|
3
3
|
import { FieldOptionProps } from '@digigov/form/inputs/Label';
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
AutoComplete,
|
|
6
6
|
AutoCompleteProps as UIAutoCompleteProps,
|
|
7
7
|
} from '@digigov/ui/form/AutoComplete';
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import { Hint } from '@digigov/ui/typography/Hint';
|
|
9
|
+
import { Base } from '@digigov/ui/utils/Base';
|
|
10
10
|
export interface AutoCompleteInputExtra
|
|
11
11
|
extends Omit<
|
|
12
12
|
UIAutoCompleteProps,
|
|
@@ -36,33 +36,38 @@ export const AutoCompleteInput: React.FC<AutoCompleteInputProps> = ({
|
|
|
36
36
|
error,
|
|
37
37
|
...props
|
|
38
38
|
}) => {
|
|
39
|
-
const suggest = useCallback(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
39
|
+
const suggest = useCallback(
|
|
40
|
+
function suggest(
|
|
41
|
+
query: string,
|
|
42
|
+
syncResults: (options: any[]) => void
|
|
43
|
+
): void {
|
|
44
|
+
syncResults(
|
|
45
|
+
query
|
|
46
|
+
? options.filter(function (option) {
|
|
47
|
+
return (
|
|
48
|
+
`${option.value} ${option.label?.primary || ''} ${
|
|
49
|
+
option.label?.secondary || ''
|
|
50
|
+
}`
|
|
51
|
+
.toLowerCase()
|
|
52
|
+
.indexOf(query.toLowerCase()) !== -1
|
|
53
|
+
);
|
|
54
|
+
})
|
|
55
|
+
: options
|
|
56
|
+
);
|
|
57
|
+
},
|
|
58
|
+
[options]
|
|
59
|
+
);
|
|
57
60
|
|
|
58
61
|
return (
|
|
59
|
-
<
|
|
62
|
+
<AutoComplete
|
|
60
63
|
multiple={type === 'choice:multiple' ? true : false}
|
|
61
64
|
source={suggest}
|
|
62
65
|
onConfirm={(value) => {
|
|
63
66
|
if (Array.isArray(value)) {
|
|
64
|
-
const selectedValues = value.map(item => item.value);
|
|
65
|
-
selectedValues.length > 0
|
|
67
|
+
const selectedValues = value.map((item) => item.value);
|
|
68
|
+
selectedValues.length > 0
|
|
69
|
+
? onChange(selectedValues)
|
|
70
|
+
: onChange(undefined);
|
|
66
71
|
} else {
|
|
67
72
|
onChange(value.value);
|
|
68
73
|
}
|
|
@@ -95,4 +100,4 @@ export const AutoCompleteInput: React.FC<AutoCompleteInputProps> = ({
|
|
|
95
100
|
);
|
|
96
101
|
};
|
|
97
102
|
|
|
98
|
-
export default AutoCompleteInput;
|
|
103
|
+
export default AutoCompleteInput;
|
|
@@ -10,24 +10,14 @@ Checkboxes are used to let a user select one or more options of a limited number
|
|
|
10
10
|
|
|
11
11
|
### Default
|
|
12
12
|
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
component="inputs/Checkboxes"
|
|
16
|
-
story="Default.tsx"
|
|
17
|
-
/>
|
|
13
|
+
<code src="@digigov/form/inputs/Checkboxes/__stories__/Default.tsx" />
|
|
14
|
+
|
|
18
15
|
|
|
19
16
|
### Conditional
|
|
20
17
|
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
component="inputs/Checkboxes"
|
|
24
|
-
story="Conditional.tsx"
|
|
25
|
-
/>
|
|
18
|
+
<code src="@digigov/form/inputs/Checkboxes/__stories__/Conditional.tsx" />
|
|
19
|
+
|
|
26
20
|
|
|
27
21
|
### With divider
|
|
28
22
|
|
|
29
|
-
<
|
|
30
|
-
packageName="@digigov/form"
|
|
31
|
-
component="inputs/Checkboxes"
|
|
32
|
-
story="WithDivider.tsx"
|
|
33
|
-
/>
|
|
23
|
+
<code src="@digigov/form/inputs/Checkboxes/__stories__/WithDivider.tsx" />
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import { ControlledFieldProps } from '@digigov/form/Field/types';
|
|
3
3
|
import { FieldOptionProps } from '@digigov/form/inputs/Label';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import {
|
|
5
|
+
Checkbox,
|
|
6
|
+
CheckboxItem,
|
|
7
|
+
CheckboxConditional,
|
|
8
|
+
} from '@digigov/ui/form/Checkbox';
|
|
8
9
|
import { useTranslation } from '@digigov/ui/i18n';
|
|
10
|
+
import { Hint } from '@digigov/ui/typography/Hint';
|
|
9
11
|
|
|
10
12
|
export interface CheckboxesProps
|
|
11
13
|
extends Omit<ControlledFieldProps, 'extra' | 'value'> {
|
|
@@ -29,34 +31,34 @@ export const Checkboxes: React.FC<CheckboxesProps> = ({
|
|
|
29
31
|
if (!value) value = [];
|
|
30
32
|
const handleChange =
|
|
31
33
|
(optionValue, idx, show) =>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
(evt): void => {
|
|
35
|
+
let newValue;
|
|
36
|
+
if (evt.currentTarget.checked) {
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
newValue = value.concat([optionValue]);
|
|
40
|
+
} else {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
newValue = value.filter((val) => val !== optionValue);
|
|
44
|
+
}
|
|
45
|
+
if (show && show.length > 0) {
|
|
46
|
+
setChecked((items) =>
|
|
47
|
+
items.map((item, index) => (index === idx ? !item : item))
|
|
48
|
+
);
|
|
49
|
+
}
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
// reset value to undefined instead of an empty array
|
|
52
|
+
// so the error state mechanism can throw validation errors
|
|
53
|
+
if (newValue.length === 0) newValue = undefined;
|
|
54
|
+
onChange(newValue);
|
|
55
|
+
};
|
|
54
56
|
const { t } = useTranslation();
|
|
55
57
|
const [checked, setChecked] = useState(
|
|
56
58
|
Array<boolean>(options.length).fill(false)
|
|
57
59
|
);
|
|
58
60
|
return (
|
|
59
|
-
<
|
|
61
|
+
<Checkbox className={className}>
|
|
60
62
|
{options.map(
|
|
61
63
|
(
|
|
62
64
|
{
|
|
@@ -103,7 +105,7 @@ export const Checkboxes: React.FC<CheckboxesProps> = ({
|
|
|
103
105
|
</React.Fragment>
|
|
104
106
|
)
|
|
105
107
|
)}
|
|
106
|
-
</
|
|
108
|
+
</Checkbox>
|
|
107
109
|
);
|
|
108
110
|
};
|
|
109
111
|
|
|
@@ -13,11 +13,4 @@ either with a textbox that validates the input or a special date picker interfac
|
|
|
13
13
|
|
|
14
14
|
### Default
|
|
15
15
|
|
|
16
|
-
<
|
|
17
|
-
packageName="@digigov/form"
|
|
18
|
-
component="inputs/DateInput"
|
|
19
|
-
story="Default.tsx"
|
|
20
|
-
/>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
<code src="@digigov/form/inputs/DateInput/__stories__/Default.tsx" />
|
|
@@ -2,8 +2,10 @@ import React, { useMemo, useState } from 'react';
|
|
|
2
2
|
import dayjs from 'dayjs';
|
|
3
3
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
4
4
|
import { UncontrolledFieldProps } from '@digigov/form/Field/types';
|
|
5
|
-
import
|
|
6
|
-
|
|
5
|
+
import {
|
|
6
|
+
DateInputContainer,
|
|
7
|
+
DateInputItem,
|
|
8
|
+
} from '@digigov/ui/form/DateInputContainer';
|
|
7
9
|
import { useTranslation } from '@digigov/ui/i18n';
|
|
8
10
|
dayjs.extend(customParseFormat);
|
|
9
11
|
|
|
@@ -75,7 +77,7 @@ const makeDate = (val) => {
|
|
|
75
77
|
};
|
|
76
78
|
|
|
77
79
|
const DatePart = ({ label, ...props }) => {
|
|
78
|
-
return <
|
|
80
|
+
return <DateInputItem {...props}>{label}</DateInputItem>;
|
|
79
81
|
};
|
|
80
82
|
|
|
81
83
|
export const DateInput = ({ name, type, ...props }) => {
|
|
@@ -12,8 +12,4 @@ Input element of type `file` let the user choose one or more files from their de
|
|
|
12
12
|
|
|
13
13
|
### Default
|
|
14
14
|
|
|
15
|
-
<
|
|
16
|
-
packageName="@digigov/form"
|
|
17
|
-
component="inputs/FileInput"
|
|
18
|
-
story="Default.tsx"
|
|
19
|
-
/>
|
|
15
|
+
<code src="@digigov/form/inputs/FileInput/__stories__/Default.tsx" />
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import { UncontrolledFieldProps } from '@digigov/form/Field/types';
|
|
3
|
-
import
|
|
4
|
-
import FileUploadContainer from '@digigov/
|
|
5
|
-
import CoreHint from '@digigov/react-core/Hint';
|
|
6
|
-
import Button from '@digigov/ui/form/Button';
|
|
3
|
+
import { Button } from '@digigov/ui/form/Button';
|
|
4
|
+
import { FileUpload, FileUploadContainer } from '@digigov/ui/form/FileUpload';
|
|
7
5
|
import { useTranslation } from '@digigov/ui/i18n';
|
|
8
|
-
import
|
|
6
|
+
import { Hint } from '@digigov/ui/typography/Hint';
|
|
7
|
+
import { Paragraph } from '@digigov/ui/typography/Paragraph';
|
|
9
8
|
export interface FileInputProps extends Omit<UncontrolledFieldProps, 'extra'> {
|
|
10
9
|
extra?: {
|
|
11
10
|
className?: string;
|
|
@@ -44,7 +43,7 @@ export const FileInput: React.FC<any> = React.forwardRef(function FileInput(
|
|
|
44
43
|
</Paragraph>
|
|
45
44
|
</>
|
|
46
45
|
) : (
|
|
47
|
-
<
|
|
46
|
+
<Hint>{t('upload.no_file')}</Hint>
|
|
48
47
|
)}
|
|
49
48
|
<FileUpload
|
|
50
49
|
ref={ref}
|