finform-react-builder 1.5.5 → 1.5.7
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 +208 -0
- package/dist/index.es.js +2523 -2391
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +22 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -208,6 +208,214 @@ export default App;
|
|
|
208
208
|
```
|
|
209
209
|
|
|
210
210
|
### Checkbox Fields
|
|
211
|
+
### Autocomplete (Single)
|
|
212
|
+
```tsx
|
|
213
|
+
{
|
|
214
|
+
name: 'country',
|
|
215
|
+
label: 'Country',
|
|
216
|
+
type: 'autocomplete',
|
|
217
|
+
placeholder: 'Search country',
|
|
218
|
+
options: [
|
|
219
|
+
{ label: 'United States', value: 'us' },
|
|
220
|
+
{ label: 'Canada', value: 'ca' },
|
|
221
|
+
],
|
|
222
|
+
// For API-driven:
|
|
223
|
+
// api_endpoint: '/common/countries?format=dropdown',
|
|
224
|
+
// api_method: 'GET',
|
|
225
|
+
// value_field: 'id',
|
|
226
|
+
// label_field: 'label',
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Autocomplete (Multiple) with Checkboxes and +N More Chips
|
|
231
|
+
```tsx
|
|
232
|
+
{
|
|
233
|
+
name: 'skills',
|
|
234
|
+
label: 'Skills',
|
|
235
|
+
type: 'autocomplete',
|
|
236
|
+
multiple: true,
|
|
237
|
+
options: [
|
|
238
|
+
{ label: 'JavaScript', value: 'javascript' },
|
|
239
|
+
{ label: 'React', value: 'react' },
|
|
240
|
+
{ label: 'TypeScript', value: 'typescript' },
|
|
241
|
+
],
|
|
242
|
+
// Stored value is an array of primitive values: ['javascript', 'react']
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
Behavior:
|
|
246
|
+
- Renders checkboxes in the dropdown when `multiple: true`.
|
|
247
|
+
- Only the first 2 selections are rendered as chips; if more, shows a `+N more` chip.
|
|
248
|
+
- Works with API-driven data using `api_endpoint`, `value_field`, `label_field`.
|
|
249
|
+
|
|
250
|
+
### Toggle (Segmented Radios)
|
|
251
|
+
```tsx
|
|
252
|
+
{
|
|
253
|
+
name: 'gender',
|
|
254
|
+
label: 'Gender',
|
|
255
|
+
type: 'toggle',
|
|
256
|
+
options: [
|
|
257
|
+
{ label: 'Male', value: 'male' },
|
|
258
|
+
{ label: 'Female', value: 'female' },
|
|
259
|
+
{ label: 'Other', value: 'other' },
|
|
260
|
+
],
|
|
261
|
+
required: true,
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Radio (Vertical)
|
|
266
|
+
```tsx
|
|
267
|
+
{
|
|
268
|
+
name: 'contactPreference',
|
|
269
|
+
label: 'Contact Preference',
|
|
270
|
+
type: 'radio',
|
|
271
|
+
options: [
|
|
272
|
+
{ label: 'Email', value: 'email' },
|
|
273
|
+
{ label: 'Phone', value: 'phone' },
|
|
274
|
+
],
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Switch
|
|
279
|
+
```tsx
|
|
280
|
+
{
|
|
281
|
+
name: 'notifications',
|
|
282
|
+
label: 'Enable Notifications',
|
|
283
|
+
type: 'switch',
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### Title and Section Headings
|
|
288
|
+
```tsx
|
|
289
|
+
{ name: 'formTitle', type: 'title', label: 'Create User', variant: 'h4', col: 12 }
|
|
290
|
+
{ name: 'detailsSection', type: 'section', label: 'Details', variant: 'h6', col: 12 }
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## 🔗 API-Driven Fields and Dependencies
|
|
294
|
+
|
|
295
|
+
### Basic API-Driven Select
|
|
296
|
+
```tsx
|
|
297
|
+
{
|
|
298
|
+
name: 'country_id',
|
|
299
|
+
label: 'Country',
|
|
300
|
+
type: 'select',
|
|
301
|
+
api_endpoint: '/common/countries?format=dropdown',
|
|
302
|
+
api_method: 'GET',
|
|
303
|
+
value_field: 'id',
|
|
304
|
+
label_field: 'label',
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Dependent Field (Conditional + depends_on)
|
|
309
|
+
```tsx
|
|
310
|
+
{
|
|
311
|
+
name: 'org_type_id',
|
|
312
|
+
label: 'Entity Type',
|
|
313
|
+
type: 'autocomplete',
|
|
314
|
+
api_endpoint: '/company/org-types/active/list',
|
|
315
|
+
api_method: 'GET',
|
|
316
|
+
value_field: 'id',
|
|
317
|
+
label_field: 'name',
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
name: 'parent_id',
|
|
321
|
+
label: 'Parent Entity',
|
|
322
|
+
type: 'autocomplete',
|
|
323
|
+
api_endpoint: '/company/offices/potential-parents/{org_type_id}?format=dropdown',
|
|
324
|
+
api_method: 'GET',
|
|
325
|
+
depends_on: 'org_type_id',
|
|
326
|
+
conditional: true,
|
|
327
|
+
value_field: 'id',
|
|
328
|
+
label_field: 'label',
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
Behavior:
|
|
332
|
+
- The dependent field (`parent_id`) is disabled until `org_type_id` has a value.
|
|
333
|
+
- When the dependency value changes, the dependent field is reset (clears previous selection).
|
|
334
|
+
|
|
335
|
+
## ✅ Validation and Submit Button Behavior
|
|
336
|
+
|
|
337
|
+
- Required fields must be filled; for arrays (e.g., multi-select), value must be non-empty.
|
|
338
|
+
- Required checkboxes must be true.
|
|
339
|
+
- Any validation error (including on non-required fields) disables submit.
|
|
340
|
+
- Single-step forms: built-in Submit button is disabled until valid.
|
|
341
|
+
- Multi-step forms: Next/Submit are disabled until the current step is valid.
|
|
342
|
+
|
|
343
|
+
Number validation example (number type):
|
|
344
|
+
```tsx
|
|
345
|
+
{
|
|
346
|
+
name: 'longitude',
|
|
347
|
+
label: 'Longitude',
|
|
348
|
+
type: 'number',
|
|
349
|
+
validation: { min: -180, max: 180, message: 'Longitude must be between -180 and 180' },
|
|
350
|
+
}
|
|
351
|
+
```
|
|
352
|
+
For `type: 'text'` number-like validation, use `pattern` or `custom` in `validation`.
|
|
353
|
+
|
|
354
|
+
## 🧭 Buttons and Button Groups
|
|
355
|
+
|
|
356
|
+
### Custom Buttons
|
|
357
|
+
```tsx
|
|
358
|
+
<FinForm
|
|
359
|
+
fields={fields}
|
|
360
|
+
buttons={[
|
|
361
|
+
{ text: 'Cancel', type: 'button', onClick: () => navigate(-1) },
|
|
362
|
+
{ text: 'Submit', type: 'submit', color: 'primary' },
|
|
363
|
+
]}
|
|
364
|
+
/>
|
|
365
|
+
```
|
|
366
|
+
- Submit (and Next) buttons are auto-disabled when the form (or current step) is invalid.
|
|
367
|
+
- Non-submit buttons (e.g., Cancel) remain clickable.
|
|
368
|
+
|
|
369
|
+
### Button Group
|
|
370
|
+
```tsx
|
|
371
|
+
<FinForm
|
|
372
|
+
fields={fields}
|
|
373
|
+
buttonGroup={{
|
|
374
|
+
position: 'right',
|
|
375
|
+
buttons: [
|
|
376
|
+
{ text: 'Previous', type: 'button' },
|
|
377
|
+
{ text: 'Next', type: 'button' },
|
|
378
|
+
{ text: 'Submit', type: 'submit' },
|
|
379
|
+
],
|
|
380
|
+
}}
|
|
381
|
+
/>
|
|
382
|
+
```
|
|
383
|
+
- Buttons with text containing "Next", "Submit", "Save", "Finish", "Complete" are treated as flow actions and auto-disabled appropriately.
|
|
384
|
+
|
|
385
|
+
## 🎨 Theming
|
|
386
|
+
```tsx
|
|
387
|
+
<FinForm
|
|
388
|
+
theme={{
|
|
389
|
+
primaryColor: '#2196f3',
|
|
390
|
+
secondaryColor: '#f50057',
|
|
391
|
+
backgroundColor: '#fafafa',
|
|
392
|
+
textColor: '#333',
|
|
393
|
+
borderRadius: 8,
|
|
394
|
+
spacing: 16,
|
|
395
|
+
typography: { fontFamily: 'Roboto, Arial, sans-serif', fontSize: 16 },
|
|
396
|
+
}}
|
|
397
|
+
fields={fields}
|
|
398
|
+
onSubmit={...}
|
|
399
|
+
/>
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
## 🖼️ Image Field
|
|
403
|
+
```tsx
|
|
404
|
+
{
|
|
405
|
+
name: 'profileImage',
|
|
406
|
+
label: 'Profile Image',
|
|
407
|
+
type: 'image',
|
|
408
|
+
defaultValue: 'https://via.placeholder.com/300x200',
|
|
409
|
+
alt: 'User profile image',
|
|
410
|
+
width: 300,
|
|
411
|
+
height: 200,
|
|
412
|
+
onClick: () => console.log('Image clicked')
|
|
413
|
+
}
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
## 🔁 onChange
|
|
417
|
+
`onChange` is fired with current form values on every change, without creating render loops, and accounts for dependent resets.
|
|
418
|
+
|
|
211
419
|
```tsx
|
|
212
420
|
{
|
|
213
421
|
name: 'newsletter',
|