@syncfusion/ej2-react-form-renderer 0.1.0-beta
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/README.md +148 -0
- package/index.d.ts +6 -0
- package/index.js +6 -0
- package/license +13 -0
- package/package.json +49 -0
- package/src/CheckboxGroup.d.ts +12 -0
- package/src/CheckboxGroup.js +48 -0
- package/src/CustomTabComponent.d.ts +13 -0
- package/src/CustomTabComponent.js +35 -0
- package/src/DataGridComponent.d.ts +29 -0
- package/src/DataGridComponent.js +160 -0
- package/src/FormRenderer.d.ts +63 -0
- package/src/FormRenderer.js +567 -0
- package/src/FormValidator.d.ts +479 -0
- package/src/FormValidator.js +579 -0
- package/src/StaticHtmlRenderer.d.ts +8 -0
- package/src/StaticHtmlRenderer.js +21 -0
- package/src/index.d.ts +6 -0
- package/src/index.js +6 -0
- package/src/json-converter.d.ts +170 -0
- package/src/json-converter.js +1180 -0
- package/src/parser.d.ts +99 -0
- package/src/parser.js +749 -0
- package/src/renderFormField.d.ts +19 -0
- package/src/renderFormField.js +202 -0
- package/src/types/FormSchema.d.ts +177 -0
- package/src/types/FormSchema.js +1 -0
- package/src/utils.js +60 -0
- package/styles/bootstrap-dark.css +26 -0
- package/styles/bootstrap.css +26 -0
- package/styles/bootstrap4.css +26 -0
- package/styles/bootstrap5-dark.css +26 -0
- package/styles/bootstrap5.3-dark.css +26 -0
- package/styles/bootstrap5.3.css +26 -0
- package/styles/bootstrap5.css +26 -0
- package/styles/fluent-dark.css +26 -0
- package/styles/fluent.css +26 -0
- package/styles/fluent2-dark.css +26 -0
- package/styles/fluent2.css +26 -0
- package/styles/form-renderer.base.css +473 -0
- package/styles/material-dark.css +26 -0
- package/styles/material.css +26 -0
- package/styles/material3-dark.css +26 -0
- package/styles/material3.css +26 -0
- package/styles/tailwind-dark.css +26 -0
- package/styles/tailwind.css +26 -0
- package/styles/tailwind3-dark.css +10 -0
- package/styles/tailwind3.css +26 -0
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type FormHTMLAttributes } from 'react';
|
|
3
|
+
export declare const VALIDATION_REGEX: {
|
|
4
|
+
[key: string]: RegExp;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Specifies the possible value types for form fields.
|
|
8
|
+
*/
|
|
9
|
+
export type FormValueType = string | number | boolean | Date | File | FileList | string[] | number[] | React.ReactNode | null | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Defines the structure for a validation rule in the form system.
|
|
12
|
+
*
|
|
13
|
+
* A ValidationRule is a two-part array containing:
|
|
14
|
+
* - A validation condition (as boolean, RegExp, number, function, etc.)
|
|
15
|
+
* - An optional custom error message to show when validation fails
|
|
16
|
+
*
|
|
17
|
+
* The first element's type depends on the specific rule:
|
|
18
|
+
* - For boolean rules (like 'required'): true/false
|
|
19
|
+
* - For pattern rules (like 'email', 'regex'): RegExp object
|
|
20
|
+
* - For range rules: number or number[] (min/max values)
|
|
21
|
+
* - For equality checks: string (field name to compare with)
|
|
22
|
+
* - For custom validation: () => boolean function
|
|
23
|
+
*
|
|
24
|
+
* ```tsx
|
|
25
|
+
* const requiredRule: ValidationRule = [true, 'This field is required'];
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export type ValidationRule = [boolean | RegExp | number | number[] | string | Date | (() => boolean), string?];
|
|
29
|
+
/**
|
|
30
|
+
* Defines the comprehensive set of validation rules that can be applied to form fields.
|
|
31
|
+
*
|
|
32
|
+
* This interface outlines all available validation types that can be configured for
|
|
33
|
+
* each field in the form. Each validation type accepts a ValidationRule containing
|
|
34
|
+
* both the validation criteria and an optional custom error message.
|
|
35
|
+
*/
|
|
36
|
+
export interface FieldValidationRules {
|
|
37
|
+
/**
|
|
38
|
+
* Validates that the field has a non-empty value. When configured with [true], the field cannot be empty, null, or undefined.
|
|
39
|
+
*
|
|
40
|
+
* ```tsx
|
|
41
|
+
* required: [true, 'This field must be filled in']
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
required?: ValidationRule;
|
|
45
|
+
/**
|
|
46
|
+
* Validates that the input conforms to a standard email address format. Checks for proper formatting with @ symbol and domain structure.
|
|
47
|
+
*
|
|
48
|
+
* ```tsx
|
|
49
|
+
* email: [true, 'Please enter a valid email address']
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
email?: ValidationRule;
|
|
53
|
+
/**
|
|
54
|
+
* Validates that the input is a properly formatted URL. Checks for proper protocol, domain structure, and path format.
|
|
55
|
+
*
|
|
56
|
+
* ```tsx
|
|
57
|
+
* url: [true, 'Please enter a valid website URL']
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
url?: ValidationRule;
|
|
61
|
+
/**
|
|
62
|
+
* Validates that the input can be parsed as a valid date. Uses Date.parse() to validate the string can be converted to a date.
|
|
63
|
+
*
|
|
64
|
+
* ```tsx
|
|
65
|
+
* date: [true, 'Please enter a valid date']
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
date?: ValidationRule;
|
|
69
|
+
/**
|
|
70
|
+
* Validates that the input follows ISO date format (YYYY-MM-DD). Ensures strict compliance with the ISO date standard.
|
|
71
|
+
*
|
|
72
|
+
* ```tsx
|
|
73
|
+
* dateIso: [true, 'Date must be in YYYY-MM-DD format']
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
dateIso?: ValidationRule;
|
|
77
|
+
/**
|
|
78
|
+
* Validates that the input contains a valid numeric value. Ensures the field can be converted to a number without errors.
|
|
79
|
+
*
|
|
80
|
+
* ```tsx
|
|
81
|
+
* number: [true, 'Please enter a number']
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
number?: ValidationRule;
|
|
85
|
+
/**
|
|
86
|
+
* Validates that the input contains only numeric digits (0-9). Rejects inputs containing decimal points, signs, letter characters or spaces.
|
|
87
|
+
*
|
|
88
|
+
* ```tsx
|
|
89
|
+
* digits: [true, 'Please enter only numeric digits']
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
digits?: ValidationRule;
|
|
93
|
+
/**
|
|
94
|
+
* Validates that the input is a valid credit card number. Checks length (13-16 digits) and applies Luhn algorithm validation.
|
|
95
|
+
*
|
|
96
|
+
* ```tsx
|
|
97
|
+
* creditCard: [true, 'Invalid credit card number']
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
creditCard?: ValidationRule;
|
|
101
|
+
/**
|
|
102
|
+
* Validates that a string has at least the specified minimum length. Takes a number as the first parameter in the validation rule.
|
|
103
|
+
*
|
|
104
|
+
* ```tsx
|
|
105
|
+
* minLength: [6, 'Must be at least 6 characters long']
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
minLength?: ValidationRule;
|
|
109
|
+
/**
|
|
110
|
+
* Validates that a string doesn't exceed the specified maximum length. Takes a number as the first parameter in the validation rule.
|
|
111
|
+
*
|
|
112
|
+
* ```tsx
|
|
113
|
+
* maxLength: [100, 'Cannot exceed 100 characters']
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
maxLength?: ValidationRule;
|
|
117
|
+
/**
|
|
118
|
+
* Validates that a string's length falls within the specified range. Takes an array of two numbers [min, max] as the first parameter.
|
|
119
|
+
*
|
|
120
|
+
* ```tsx
|
|
121
|
+
* rangeLength: [[8, 16], 'Must be between 8 and 16 characters']
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
rangeLength?: ValidationRule;
|
|
125
|
+
/**
|
|
126
|
+
* Validates that a numeric value is at least the specified minimum. Takes a number as the first parameter in the validation rule.
|
|
127
|
+
*
|
|
128
|
+
* ```tsx
|
|
129
|
+
* min: [18, 'Value must be at least 18']
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
min?: ValidationRule;
|
|
133
|
+
/**
|
|
134
|
+
* Validates that a numeric value doesn't exceed the specified maximum. Takes a number as the first parameter in the validation rule.
|
|
135
|
+
*
|
|
136
|
+
* ```tsx
|
|
137
|
+
* max: [100, 'Value cannot exceed 100']
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
max?: ValidationRule;
|
|
141
|
+
/**
|
|
142
|
+
* Validates that a numeric value falls within the specified range. Takes an array of two numbers [min, max] as the first parameter.
|
|
143
|
+
*
|
|
144
|
+
* ```tsx
|
|
145
|
+
* range: [[1, 10], 'Value must be between 1 and 10']
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
range?: ValidationRule;
|
|
149
|
+
/**
|
|
150
|
+
* Validates that the input matches the specified regular expression pattern. Takes a RegExp object or a string pattern as the first parameter.
|
|
151
|
+
*
|
|
152
|
+
* ```tsx
|
|
153
|
+
* regex: [/^[A-Z][a-z]+$/, 'Must start with capital letter followed by lowercase letters']
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
regex?: ValidationRule;
|
|
157
|
+
/**
|
|
158
|
+
* Validates that the input conforms to a standard telephone number format. Checks for proper formatting of phone numbers with optional country code.
|
|
159
|
+
*
|
|
160
|
+
* ```tsx
|
|
161
|
+
* tel: [true, 'Please enter a valid phone number']
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
tel?: ValidationRule;
|
|
165
|
+
/**
|
|
166
|
+
* Validates that the field's value exactly matches another field's value. Takes the name of another field as the first parameter.
|
|
167
|
+
*
|
|
168
|
+
* ```tsx
|
|
169
|
+
* equalTo: ['password', 'Passwords must match']
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
equalTo?: ValidationRule;
|
|
173
|
+
/**
|
|
174
|
+
* Allows for completely custom validation logic as a function.
|
|
175
|
+
*
|
|
176
|
+
* This function receives the field value and should return either:
|
|
177
|
+
* - A string containing an error message if validation fails
|
|
178
|
+
* - null if validation passes
|
|
179
|
+
*
|
|
180
|
+
* ```tsx
|
|
181
|
+
* customValidator: (value) => {
|
|
182
|
+
* if (typeof value === 'string' && !value.includes('@company.com')) {
|
|
183
|
+
* return 'Email must be a company email';
|
|
184
|
+
* }
|
|
185
|
+
* return null;
|
|
186
|
+
* }
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
customValidator?: (value: FormValueType) => string | null;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Defines the complete validation schema for a form by mapping field names to their validation rules.
|
|
193
|
+
*
|
|
194
|
+
* This interface creates a dictionary where each key is a field name and each value
|
|
195
|
+
* is an object containing all validation rules that apply to that field. The ValidationRules
|
|
196
|
+
* object is passed to the Form component to establish the validation criteria for the entire form.
|
|
197
|
+
*
|
|
198
|
+
* ```tsx
|
|
199
|
+
* const validationSchema: ValidationRules = {
|
|
200
|
+
* username: {
|
|
201
|
+
* required: [true, 'Username is required'],
|
|
202
|
+
* minLength: [3, 'Username must be at least 3 characters']
|
|
203
|
+
* },
|
|
204
|
+
*
|
|
205
|
+
* email: {
|
|
206
|
+
* required: [true, 'Email is required'],
|
|
207
|
+
* email: [true, 'Please enter a valid email address']
|
|
208
|
+
* }
|
|
209
|
+
* };
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
export interface ValidationRules {
|
|
213
|
+
[fieldName: string]: FieldValidationRules;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Specifies the state and callback properties provided by the Form component.
|
|
217
|
+
*
|
|
218
|
+
* The FormState interface provides comprehensive access to the form's state
|
|
219
|
+
* and behavior through the onFormStateChange callback. It allows parent components
|
|
220
|
+
* to build custom form UIs with full access to validation state, field values, and form event handlers.
|
|
221
|
+
*/
|
|
222
|
+
export interface FormState {
|
|
223
|
+
/**
|
|
224
|
+
* Specifies the current values for all form fields indexed by field name.
|
|
225
|
+
* Access individual values using: values.fieldName
|
|
226
|
+
*
|
|
227
|
+
* ```tsx
|
|
228
|
+
* const username = formState.values.username;
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
values: Record<string, FormValueType>;
|
|
232
|
+
/**
|
|
233
|
+
* Specifies the current validation errors for all fields indexed by field name.
|
|
234
|
+
* Fields without errors won't appear in this object.
|
|
235
|
+
*
|
|
236
|
+
*/
|
|
237
|
+
errors: Record<string, string>;
|
|
238
|
+
/**
|
|
239
|
+
* Specifies which fields in the form are valid (have no validation errors).
|
|
240
|
+
*
|
|
241
|
+
*/
|
|
242
|
+
valid: Record<string, boolean>;
|
|
243
|
+
/**
|
|
244
|
+
* Specifies if the form can be submitted. True when all fields are valid;
|
|
245
|
+
* otherwise, all fields are marked as touched when attempted to submit.
|
|
246
|
+
*/
|
|
247
|
+
allowSubmit: boolean;
|
|
248
|
+
/**
|
|
249
|
+
* Specifies if the form has been submitted at least once.
|
|
250
|
+
* True after a submission attempt regardless of validation result.
|
|
251
|
+
*/
|
|
252
|
+
submitted: boolean;
|
|
253
|
+
/**
|
|
254
|
+
* Specifies which fields in the form have been modified from their initial values.
|
|
255
|
+
*
|
|
256
|
+
*/
|
|
257
|
+
modified: Record<string, boolean>;
|
|
258
|
+
/**
|
|
259
|
+
* Specifies which fields have been touched (blurred after interaction).
|
|
260
|
+
* Useful for determining when to display validation messages.
|
|
261
|
+
*
|
|
262
|
+
*/
|
|
263
|
+
touched: Record<string, boolean>;
|
|
264
|
+
/**
|
|
265
|
+
* Specifies which fields have been visited (received focus).
|
|
266
|
+
*
|
|
267
|
+
*/
|
|
268
|
+
visited: Record<string, boolean>;
|
|
269
|
+
/**
|
|
270
|
+
* Specifies a dictionary of field names for easy access to form fields.
|
|
271
|
+
*
|
|
272
|
+
*/
|
|
273
|
+
fieldNames: Record<string, string>;
|
|
274
|
+
/**
|
|
275
|
+
* Specifies the callback function to handle field value changes.
|
|
276
|
+
* Use this instead of directly modifying input elements.
|
|
277
|
+
*
|
|
278
|
+
* @param name - The name of the field to update
|
|
279
|
+
* @param options - Object containing the new value for the field.
|
|
280
|
+
* @event onChange
|
|
281
|
+
*/
|
|
282
|
+
onChange(name: string, options: {
|
|
283
|
+
value: FormValueType;
|
|
284
|
+
}): void;
|
|
285
|
+
/**
|
|
286
|
+
* Specifies the callback function for when a field loses focus.
|
|
287
|
+
*
|
|
288
|
+
* @param fieldName - The name of the field that lost focus.
|
|
289
|
+
* @event onBlur
|
|
290
|
+
*/
|
|
291
|
+
onBlur(fieldName: string): void;
|
|
292
|
+
/**
|
|
293
|
+
* Specifies the callback function for when a field receives focus.
|
|
294
|
+
* Records the field as visited.
|
|
295
|
+
*
|
|
296
|
+
* @param fieldName - The name of the field that received focus.
|
|
297
|
+
* @event onFocus
|
|
298
|
+
*/
|
|
299
|
+
onFocus(fieldName: string): void;
|
|
300
|
+
/**
|
|
301
|
+
* Specifies the callback function to reset the form to its initial state.
|
|
302
|
+
* Clears all values, errors, and interaction states.
|
|
303
|
+
*
|
|
304
|
+
* @event onFormReset
|
|
305
|
+
*/
|
|
306
|
+
onFormReset(): void;
|
|
307
|
+
/**
|
|
308
|
+
* Specifies the callback function to submit the form.
|
|
309
|
+
* Can be used with a submit button's onClick event.
|
|
310
|
+
*
|
|
311
|
+
* @param event - The synthetic event from the form submission.
|
|
312
|
+
* @event onSubmit
|
|
313
|
+
*/
|
|
314
|
+
onSubmit(event: React.SyntheticEvent): void;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Specifies initial values for form fields. Maps field names to their default values when the form loads.
|
|
318
|
+
*
|
|
319
|
+
* ```tsx
|
|
320
|
+
* const initialValues: FormInitialValues = {
|
|
321
|
+
* username: 'john_doe'
|
|
322
|
+
* };
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
export interface FormInitialValues {
|
|
326
|
+
[fieldName: string]: FormValueType;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Specifies the props interface for the Form component.
|
|
330
|
+
*/
|
|
331
|
+
export interface FormProps {
|
|
332
|
+
/**
|
|
333
|
+
* Specifies the validation rules for each form field. This object defines constraints that form fields must satisfy.
|
|
334
|
+
*/
|
|
335
|
+
rules: ValidationRules;
|
|
336
|
+
/**
|
|
337
|
+
* Specifies the callback fired when form is submitted and all validation rules pass.
|
|
338
|
+
*
|
|
339
|
+
* @param {Record<string, FormValueType>} data - Specifies the form data containing all field values
|
|
340
|
+
* @event onSubmit
|
|
341
|
+
*/
|
|
342
|
+
onSubmit?: (data: Record<string, FormValueType>) => void;
|
|
343
|
+
/**
|
|
344
|
+
* Specifies the callback fired when form state changes.
|
|
345
|
+
* This can be used to access form state from parent components for custom UI rendering.
|
|
346
|
+
*
|
|
347
|
+
* @param {FormState} formState - The current state of the form
|
|
348
|
+
* @event onFormStateChange
|
|
349
|
+
*/
|
|
350
|
+
onFormStateChange?: (formState: FormState) => void;
|
|
351
|
+
/**
|
|
352
|
+
* Specifies the initial values for form fields. These values populate the form.
|
|
353
|
+
*
|
|
354
|
+
* @default -
|
|
355
|
+
*/
|
|
356
|
+
initialValues?: FormInitialValues;
|
|
357
|
+
/**
|
|
358
|
+
* Specifies whether to trigger validation on every input change. When true, validation occurs on each keystroke, providing immediate feedback.
|
|
359
|
+
*
|
|
360
|
+
* @default false
|
|
361
|
+
*/
|
|
362
|
+
validateOnChange?: boolean;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Specifies the FormValidator interface for imperative methods.
|
|
366
|
+
*/
|
|
367
|
+
export interface IFormValidator extends FormProps {
|
|
368
|
+
/**
|
|
369
|
+
* Validates the entire form against all defined rules.
|
|
370
|
+
*
|
|
371
|
+
* @returns {boolean} - Returns true if the form is valid, false otherwise.
|
|
372
|
+
*/
|
|
373
|
+
validate(): boolean;
|
|
374
|
+
/**
|
|
375
|
+
* Resets the form to its initial state, clearing all values, errors, and interaction states.
|
|
376
|
+
*
|
|
377
|
+
* @returns {void}
|
|
378
|
+
*/
|
|
379
|
+
reset(): void;
|
|
380
|
+
/**
|
|
381
|
+
* Validates a specific field against its defined rules.
|
|
382
|
+
*
|
|
383
|
+
* @param {string} fieldName - Specifies the name of the field to validate
|
|
384
|
+
* @returns {boolean} - Returns true if the field is valid, false otherwise
|
|
385
|
+
*/
|
|
386
|
+
validateField(fieldName: string): boolean;
|
|
387
|
+
/**
|
|
388
|
+
* Provides access to the underlying HTML form element.
|
|
389
|
+
*
|
|
390
|
+
* @private
|
|
391
|
+
*/
|
|
392
|
+
element?: HTMLFormElement;
|
|
393
|
+
}
|
|
394
|
+
type FormComponentProps = FormProps & Omit<FormHTMLAttributes<HTMLFormElement>, 'onSubmit'>;
|
|
395
|
+
/**
|
|
396
|
+
* Provides a form component with built-in validation functionality. Manages form state tracking,
|
|
397
|
+
* field validation, and submission handling.
|
|
398
|
+
*
|
|
399
|
+
* ```typescript
|
|
400
|
+
* import { Form, FormField, FormState } from '@syncfusion/react-inputs';
|
|
401
|
+
*
|
|
402
|
+
* const [formState, setFormState] = useState<FormState>();
|
|
403
|
+
*
|
|
404
|
+
* <Form
|
|
405
|
+
* rules={{ username: { required: [true, 'Username is required'] } }}
|
|
406
|
+
* onSubmit={data => console.log(data)}
|
|
407
|
+
* onFormStateChange={setFormState} >
|
|
408
|
+
* <FormField name="username">
|
|
409
|
+
* <input
|
|
410
|
+
* name="username"
|
|
411
|
+
* value={(formState?.values.username || '') as string}
|
|
412
|
+
* onChange={(e) => formState?.onChange('username', { value: e.target.value })}
|
|
413
|
+
* onBlur={() => formState?.onBlur('username')}
|
|
414
|
+
* onFocus={() => formState?.onFocus('username')}
|
|
415
|
+
* />
|
|
416
|
+
* {formState?.errors?.username && (<div className="error">{formState.errors.username}</div>)}
|
|
417
|
+
* </FormField>
|
|
418
|
+
* <button type="submit">Submit</button>
|
|
419
|
+
* </Form>
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
export declare const Form: React.ForwardRefExoticComponent<FormComponentProps & React.RefAttributes<IFormValidator>>;
|
|
423
|
+
/**
|
|
424
|
+
* Specifies the properties for the FormField component.
|
|
425
|
+
*/
|
|
426
|
+
export interface FormFieldProps {
|
|
427
|
+
/**
|
|
428
|
+
* Specifies the name of the field that must match a key in the rules object. This is required for proper validation.
|
|
429
|
+
*/
|
|
430
|
+
name: string;
|
|
431
|
+
/**
|
|
432
|
+
* Specifies the children content for the form field. Children should include the actual form control elements like inputs, textarea, etc.
|
|
433
|
+
*/
|
|
434
|
+
children: React.ReactNode;
|
|
435
|
+
/**
|
|
436
|
+
* Specifies field-level validation rules that apply only to this specific field. These rules override any form-level rules
|
|
437
|
+
* with the same name defined in the Form component's rules. This allows for field-specific validation that takes
|
|
438
|
+
* precedence over form-wide defaults.
|
|
439
|
+
*
|
|
440
|
+
* @default undefined
|
|
441
|
+
*/
|
|
442
|
+
rules?: FieldValidationRules;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Specifies a component that connects form inputs with validation rules. The FormField component provides
|
|
446
|
+
* an easy way to integrate form controls with the Form validation system, handling state management and
|
|
447
|
+
* validation automatically.
|
|
448
|
+
*
|
|
449
|
+
* ```typescript
|
|
450
|
+
* const [formState, setFormState] = useState<FormState>();
|
|
451
|
+
*
|
|
452
|
+
* <Form
|
|
453
|
+
* rules={{
|
|
454
|
+
* username: { required: [true, 'Username is required'] }
|
|
455
|
+
* }}
|
|
456
|
+
* onSubmit={data => console.log(data)}
|
|
457
|
+
* onFormStateChange={setFormState}
|
|
458
|
+
* >
|
|
459
|
+
* <FormField name="username">
|
|
460
|
+
* <input
|
|
461
|
+
* name="username"
|
|
462
|
+
* value={formState?.values.username || ''}
|
|
463
|
+
* onChange={(e) => formState?.onChange('username', { value: e.target.value })}
|
|
464
|
+
* onBlur={() => formState?.onBlur('username')}
|
|
465
|
+
* onFocus={() => formState?.onFocus('username')}
|
|
466
|
+
* />
|
|
467
|
+
* {formState?.touched?.username && formState?.errors?.username && (
|
|
468
|
+
* <div className="error">{formState.errors.username}</div>
|
|
469
|
+
* )}
|
|
470
|
+
* </FormField>
|
|
471
|
+
* <button type="submit">Submit</button>
|
|
472
|
+
* </Form>
|
|
473
|
+
* ```
|
|
474
|
+
*
|
|
475
|
+
* @param {IFormFieldProps} props - Specifies the form field configuration properties
|
|
476
|
+
* @returns {React.ReactNode} - Returns the children with access to form validation context
|
|
477
|
+
*/
|
|
478
|
+
export declare const FormField: React.FC<FormFieldProps>;
|
|
479
|
+
export {};
|