Skip to content

Commit c7eb884

Browse files
authored
Adding support for form field messages (#5)
1 parent f29323c commit c7eb884

File tree

17 files changed

+563
-286
lines changed

17 files changed

+563
-286
lines changed

README.md

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- [Form field](#form-field)
3737
- [Form field types](#form-field-types)
3838
- [Accessing the wizard data](#accessing-the-wizard-data)
39+
- [Custom validation messages](#custom-validation-messages)
3940
- [🎨 Theme](#-theme)
4041
- [CodeSandbox examples](#codesandbox-examples)
4142
- [⛏️ Built With](#️-built-with)
@@ -89,14 +90,14 @@ The example shows a simple wizard with two pages.
8990

9091
## ⚙️ Properties
9192

92-
| Name | Description | Default |
93-
| :---------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
94-
| `strict` | Enables validation rules for all input types on all pages. The component prevents the user from progressing until the errors in the current step have been corrected | false |
95-
| `theme` | [Theme](#🎨-theme) object for customized styling | |
96-
| `highlightFieldsOnValidation` | Highlights the fields when the validation fails or succeeds | false |
97-
| `pages` | Collection of [Page](#Page) object | |
98-
| `onFinish` | Callback executed on final step | |
99-
| `RTL` | Enables right to left mode | false |
93+
| Name | Description | Default |
94+
| :---------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
95+
| `strict` | Validation rules are applied to all inputs that have been marked for validation or that are required. The component prevents the user from moving on until the current step's errors have been fixed. | false |
96+
| `theme` | [Theme](#🎨-theme) object for customized styling | |
97+
| `highlightFieldsOnValidation` | Highlights the fields when the validation fails or succeeds | false |
98+
| `pages` | Collection of [Page](#Page) object | |
99+
| `onFinish` | Callback executed on final step | |
100+
| `RTL` | Enables right to left mode | false |
100101

101102
## Page
102103

@@ -160,14 +161,15 @@ Here is an examples how to define pages in the wizard. We are defining two pages
160161

161162
Form field represents an input field in the wizard. Form field is used to define the label, type, validation rules, and other properties.
162163

163-
| Name | Description | Type |
164-
| :------------ | :---------------------------------- | :-------- |
165-
| isRequired | Marks the field as required | boolean |
166-
| label | Label for the field | string |
167-
| name | Name of the Field | string |
168-
| selectOptions | Use this prop when type is "select" | Array |
169-
| type | Type of Field | InputType |
170-
| validate | Enables validation for the field | boolean |
164+
| Name | Description | Type |
165+
| :---------------- | :---------------------------------------------------------- | :-------- |
166+
| isRequired | Marks the field as required | boolean |
167+
| label | Label for the field | string |
168+
| name | Name of the Field | string |
169+
| selectOptions | Use this prop when type is "select" | Array |
170+
| type | Type of Field | InputType |
171+
| validate | Enables validation for the field | boolean |
172+
| validationMessage | Custom validation message to be shown on validation failure | boolean |
171173

172174
> Fields marked as required are automatically validated. If you set `isRequired` to `false` and `validate` to `true`, the wizard will validate and flag the errors, but the step itself will not be marked as invalid.
173175
@@ -235,6 +237,28 @@ For the getting started example, the `onFinish` callback will receive an object
235237
}
236238
```
237239

240+
## Custom validation messages
241+
242+
Validation messages are enabled by default for all fields. However, the `validationMessage` property allows you to customize the message for each field.
243+
244+
```jsx
245+
<Wizard
246+
pages={[
247+
{
248+
title: "Introduction",
249+
fields: [
250+
{
251+
label: "First Name",
252+
name: "firstName",
253+
type: "text",
254+
isRequired: true,
255+
validationMessage: "Please enter your first name",
256+
},
257+
],
258+
},
259+
]}
260+
```
261+
238262
## 🎨 Theme
239263

240264
Customize the look and feel of the Wizard through the `theme` object.

coverage/coverage-final.json

Lines changed: 3 additions & 2 deletions
Large diffs are not rendered by default.

coverage/index.html

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,30 @@ <h1>All files</h1>
2323
<div class='clearfix'>
2424

2525
<div class='fl pad1y space-right2'>
26-
<span class="strong">69.51% </span>
26+
<span class="strong">71.37% </span>
2727
<span class="quiet">Statements</span>
28-
<span class='fraction'>707/1017</span>
28+
<span class='fraction'>743/1041</span>
2929
</div>
3030

3131

3232
<div class='fl pad1y space-right2'>
33-
<span class="strong">76.59% </span>
33+
<span class="strong">77.55% </span>
3434
<span class="quiet">Branches</span>
35-
<span class='fraction'>108/141</span>
35+
<span class='fraction'>114/147</span>
3636
</div>
3737

3838

3939
<div class='fl pad1y space-right2'>
40-
<span class="strong">51.21% </span>
40+
<span class="strong">53.48% </span>
4141
<span class="quiet">Functions</span>
42-
<span class='fraction'>21/41</span>
42+
<span class='fraction'>23/43</span>
4343
</div>
4444

4545

4646
<div class='fl pad1y space-right2'>
47-
<span class="strong">69.51% </span>
47+
<span class="strong">71.37% </span>
4848
<span class="quiet">Lines</span>
49-
<span class='fraction'>707/1017</span>
49+
<span class='fraction'>743/1041</span>
5050
</div>
5151

5252

@@ -110,17 +110,17 @@ <h1>All files</h1>
110110

111111
<tr>
112112
<td class="file high" data-value="react-wizardly/src/components/form-field"><a href="react-wizardly/src/components/form-field/index.html">react-wizardly/src/components/form-field</a></td>
113-
<td data-value="83.88" class="pic high">
114-
<div class="chart"><div class="cover-fill" style="width: 83%"></div><div class="cover-empty" style="width: 17%"></div></div>
113+
<td data-value="90.63" class="pic high">
114+
<div class="chart"><div class="cover-fill" style="width: 90%"></div><div class="cover-empty" style="width: 10%"></div></div>
115115
</td>
116-
<td data-value="83.88" class="pct high">83.88%</td>
117-
<td data-value="211" class="abs high">177/211</td>
118-
<td data-value="80.48" class="pct high">80.48%</td>
119-
<td data-value="41" class="abs high">33/41</td>
116+
<td data-value="90.63" class="pct high">90.63%</td>
117+
<td data-value="235" class="abs high">213/235</td>
118+
<td data-value="82.97" class="pct high">82.97%</td>
119+
<td data-value="47" class="abs high">39/47</td>
120120
<td data-value="100" class="pct high">100%</td>
121-
<td data-value="2" class="abs high">2/2</td>
122-
<td data-value="83.88" class="pct high">83.88%</td>
123-
<td data-value="211" class="abs high">177/211</td>
121+
<td data-value="4" class="abs high">4/4</td>
122+
<td data-value="90.63" class="pct high">90.63%</td>
123+
<td data-value="235" class="abs high">213/235</td>
124124
</tr>
125125

126126
<tr>
@@ -206,7 +206,7 @@ <h1>All files</h1>
206206
<div class='footer quiet pad2 space-top1 center small'>
207207
Code coverage generated by
208208
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
209-
at Sun May 01 2022 16:35:14 GMT+0530 (India Standard Time)
209+
at Wed May 04 2022 13:08:22 GMT+0530 (India Standard Time)
210210
</div>
211211
<script src="prettify.js"></script>
212212
<script>

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
],
3737
"dependencies": {
3838
"classnames": "^2.3.1",
39-
"nanoid": "^3.3.3"
39+
"nanoid": "^3.3.4"
4040
},
4141
"peerDependencies": {
4242
"react": "^17.0.0",
@@ -96,14 +96,14 @@
9696
"@babel/preset-react": "^7.16.7",
9797
"@babel/runtime": "^7.17.9",
9898
"@testing-library/jest-dom": "^5.16.4",
99-
"@testing-library/react": "^13.1.1",
99+
"@testing-library/react": "^13.2.0",
100100
"@types/react": "^18.0.8",
101101
"@types/react-dom": "^18.0.3",
102-
"@typescript-eslint/eslint-plugin": "^5.21.0",
103-
"@typescript-eslint/parser": "^5.21.0",
104-
"@vitejs/plugin-react": "^1.3.1",
102+
"@typescript-eslint/eslint-plugin": "^5.22.0",
103+
"@typescript-eslint/parser": "^5.22.0",
104+
"@vitejs/plugin-react": "^1.3.2",
105105
"@webpack-cli/generators": "^2.4.2",
106-
"autoprefixer": "^10.4.5",
106+
"autoprefixer": "^10.4.7",
107107
"babel-loader": "^8.2.5",
108108
"c8": "^7.11.2",
109109
"copy-webpack-plugin": "^10.2.4",
@@ -122,21 +122,21 @@
122122
"mini-css-extract-plugin": "^2.6.0",
123123
"postcss": "^8.4.13",
124124
"postcss-loader": "^6.2.1",
125-
"postcss-preset-env": "^7.4.4",
125+
"postcss-preset-env": "^7.5.0",
126126
"prettier": "^2.6.2",
127127
"pretty-quick": "^3.1.3",
128128
"react": "^18.1.0",
129129
"react-dom": "^18.1.0",
130130
"sass": "^1.51.0",
131131
"sass-loader": "^12.6.0",
132132
"style-loader": "^3.3.1",
133-
"stylelint": "^14.8.1",
133+
"stylelint": "^14.8.2",
134134
"stylelint-config-standard": "^25.0.0",
135135
"terser-webpack-plugin": "^5.3.1",
136136
"ts-loader": "^9.3.0",
137137
"typescript": "^4.6.4",
138-
"vite": "^2.9.6",
139-
"vitest": "^0.10.0",
138+
"vite": "^2.9.7",
139+
"vitest": "^0.10.2",
140140
"webpack": "^5.72.0",
141141
"webpack-bundle-analyzer": "^4.5.0",
142142
"webpack-cli": "^4.9.2",

0 commit comments

Comments
 (0)