datasync-dynamic-form 1.3.4 → 1.3.6

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.
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
2
  import React, { Component, useImperativeHandle, forwardRef } from "react";
12
3
  import Multiselect from 'multiselect-react-dropdown';
@@ -15,11 +6,13 @@ import { DsBlob } from "datasync-blob";
15
6
  import { DsPdf } from "datasync-pdf";
16
7
  // reactstrap components
17
8
  import { Button, Label, FormGroup, Input, InputGroupText, InputGroup, Row as ReactstrapRow, Col as ReactstrapCol, } from "reactstrap";
18
- const debugging = false;
9
+ import "./flex-grid.css";
10
+ const FlexRow = ({ className, ...props }) => (_jsx(ReactstrapRow, { className: ["flex-row", className].filter(Boolean).join(" "), ...props }));
11
+ const FlexCol = ({ className, ...props }) => (_jsx(ReactstrapCol, { className: ["flex-col", className].filter(Boolean).join(" "), ...props }));
19
12
  const globals = {
20
13
  parameters: {
21
- debugging: debugging,
22
14
  local: true,
15
+ production: false,
23
16
  use_navigate: false,
24
17
  save_failed_alert: false,
25
18
  form_version: "1.0",
@@ -40,19 +33,19 @@ export class DsDynamicForm extends Component {
40
33
  */
41
34
  this.updatePageDomElement = (p_pageIndex, p_page_isVisible) => {
42
35
  let pageObject = document.getElementById(`dsdf_page_${p_pageIndex}`);
43
- if (globals.parameters.debugging)
36
+ if (this.debugging)
44
37
  console.log(`updatePageDomElement = (${p_pageIndex}, ${p_page_isVisible ? "show" : "hide"})`);
45
38
  if (!pageObject) {
46
39
  console.error(`Page element with id 'dsdf_page_${p_pageIndex}' not found`);
47
40
  return;
48
41
  }
49
- if (globals.parameters.debugging)
42
+ if (this.debugging)
50
43
  console.log("pageObject.classList(before)->", pageObject.classList);
51
44
  if (p_page_isVisible)
52
45
  pageObject.classList.add("page_visible");
53
46
  else
54
47
  pageObject.classList.remove("page_visible");
55
- if (globals.parameters.debugging)
48
+ if (this.debugging)
56
49
  console.log("pageObject.classList(after)->", pageObject.classList);
57
50
  };
58
51
  /**
@@ -72,7 +65,7 @@ export class DsDynamicForm extends Component {
72
65
  if (this.props.foreign_keys && typeof this.props.foreign_keys !== "object")
73
66
  throw new Error("foreign_keys must be a json object !");
74
67
  this.local_data_blob.data_tier = Object.assign(this.props.foreign_keys ? this.props.foreign_keys : {}, duplicate_data_tier);
75
- if (globals.parameters.debugging)
68
+ if (this.debugging)
76
69
  console.log("clearForm->this.local_data_blob.data_tier =>", this.local_data_blob.data_tier);
77
70
  };
78
71
  this.getFieldData = (fieldName) => {
@@ -82,7 +75,7 @@ export class DsDynamicForm extends Component {
82
75
  };
83
76
  this.setFieldData = (fieldName, value) => {
84
77
  try {
85
- if (globals.parameters.debugging)
78
+ if (this.debugging)
86
79
  console.log("setFieldData:fieldName ->", fieldName, " value ->", value);
87
80
  let duplicate_data_tier = JSON.parse(JSON.stringify(this.local_data_blob.data_tier));
88
81
  duplicate_data_tier[fieldName] = value;
@@ -109,7 +102,7 @@ export class DsDynamicForm extends Component {
109
102
  this.getFieldError = (pFieldObject) => {
110
103
  /** Return data value form field object */
111
104
  try {
112
- if (globals.parameters.debugging)
105
+ if (this.debugging)
113
106
  console.log(`getFieldError(${JSON.stringify(pFieldObject)}) -> ${this.state.fieldError}`);
114
107
  let dbg = (this.state.fieldError && this.state.fieldError[pFieldObject.name]) ? this.state.fieldError[pFieldObject.name] : "";
115
108
  return `${dbg}`;
@@ -187,8 +180,11 @@ export class DsDynamicForm extends Component {
187
180
  this.onFormSavedLocalHandler, this.onFormUpdatedLocalHandler, this.onFormFailedLocalHandler, null);
188
181
  };
189
182
  /** Form Handlers */
190
- this.onClickSubmitFormHandler = (event) => __awaiter(this, void 0, void 0, function* () {
183
+ this.onClickSubmitFormHandler = async (event) => {
191
184
  try {
185
+ //Trigger handler as user click submit button in order to animate checking + saving progress bar.
186
+ if (this.props.onBeforeFormSubmit)
187
+ this.props.onBeforeFormSubmit(this.local_data_blob);
192
188
  if (event)
193
189
  event.preventDefault();
194
190
  //Force all fields check
@@ -219,7 +215,7 @@ export class DsDynamicForm extends Component {
219
215
  if (!canSubmit) {
220
216
  // Scroll to the first field with error only on submit
221
217
  if (firstErrFieldName) {
222
- if (globals.parameters.debugging)
218
+ if (this.debugging)
223
219
  console.log("WScrollTo invoked :-)");
224
220
  WScrollTo(firstErrFieldName);
225
221
  }
@@ -232,7 +228,7 @@ export class DsDynamicForm extends Component {
232
228
  }
233
229
  //Invoke onFormSubmit props
234
230
  if (this.props.onFormSubmit) {
235
- if (globals.parameters.debugging)
231
+ if (this.debugging)
236
232
  alert("onFormSubmit => filter log with AsyncDebug:: prefixe");
237
233
  //If props function return false then cancel form submit and do not save !
238
234
  this.props.onFormSubmit(this.local_data_blob);
@@ -247,12 +243,55 @@ export class DsDynamicForm extends Component {
247
243
  console.error(`onClickSubmitFormHandler raises "${error}"`);
248
244
  return false;
249
245
  }
250
- });
246
+ };
247
+ this.checkCurrentPage = async (event) => {
248
+ try {
249
+ /*Trigger typically called from external to check curetn page fields.
250
+ returns true when all fields are correct. User is then allowed to pursue to next page*/
251
+ if (event)
252
+ event.preventDefault();
253
+ //Force all fields check
254
+ let canSubmit = true;
255
+ let firstErrFieldName = null;
256
+ let iPage = this.props.active_page || 0; //Process only current page
257
+ let iRow = 0;
258
+ while (iRow < this.state.form.Pages[iPage].Rows.length) {
259
+ let iCol = 0;
260
+ while (iCol < this.state.form.Pages[iPage].Rows[iRow].Cols.length) {
261
+ let ii = 0;
262
+ while (ii < this.state.form.Pages[iPage].Rows[iRow].Cols[iCol].Fields.length) {
263
+ const field = this.state.form.Pages[iPage].Rows[iRow].Cols[iCol].Fields[ii];
264
+ const isValid = this.checkValidation(field);
265
+ if (!isValid && firstErrFieldName === null) {
266
+ firstErrFieldName = field.name;
267
+ }
268
+ canSubmit = canSubmit && isValid;
269
+ ii++;
270
+ }
271
+ iCol++;
272
+ }
273
+ iRow++;
274
+ }
275
+ if (!canSubmit) {
276
+ let err_message = `La page ${iPage} de formulaire comporte des erreurs !`;
277
+ if (this.props.onFormFailed)
278
+ this.props.onFormFailed(err_message);
279
+ else
280
+ console.error(`checkCurrentPage ${iPage} raises "${err_message}"`);
281
+ return false;
282
+ }
283
+ return canSubmit;
284
+ }
285
+ catch (error) {
286
+ console.error(`checkCurrentPage raises "${error}"`);
287
+ return false;
288
+ }
289
+ };
251
290
  this.onFormSavedLocalHandler = (blob) => {
252
291
  if (this.props.onFormSaved)
253
292
  this.props.onFormSaved(blob);
254
293
  else
255
- console.error("DynamicForm3Tiers2.onFormSaved props is not defined !");
294
+ console.error("DsDynamicForm.onFormSaved props is not defined !");
256
295
  //clear form
257
296
  if (this.props.clearOnSave)
258
297
  this.clearForm();
@@ -265,7 +304,7 @@ export class DsDynamicForm extends Component {
265
304
  if (this.props.onFormUpdated)
266
305
  this.props.onFormUpdated(blob);
267
306
  else
268
- console.error("DynamicForm3Tiers2.onFormUpdated props is not defined !");
307
+ console.error("DsDynamicForm.onFormUpdated props is not defined !");
269
308
  //clear form
270
309
  if (this.props.clearOnUpdate)
271
310
  this.clearForm();
@@ -281,10 +320,18 @@ export class DsDynamicForm extends Component {
281
320
  if (this.props.onFormFailed)
282
321
  this.props.onFormFailed(err);
283
322
  else {
284
- console.error("DynamicForm3Tiers2.onFormFailed props is not defined !");
323
+ console.error("DsDynamicForm.onFormFailed props is not defined !");
285
324
  alert("Erreur de sauvegarde !!!");
286
325
  }
287
326
  };
327
+ this.onBlobErrorLocalHandler = (errorObject) => {
328
+ if (this.props.onBlobErrorHandler)
329
+ this.props.onBlobErrorHandler(errorObject);
330
+ else {
331
+ console.error("DsDynamicForm.onBlobErrorHandler props is not defined !");
332
+ alert(errorObject.message);
333
+ }
334
+ };
288
335
  this.checkValidation = (pFieldObject) => {
289
336
  /** Get field properties */
290
337
  let min = pFieldObject.min_length || 0;
@@ -313,7 +360,7 @@ export class DsDynamicForm extends Component {
313
360
  }
314
361
  if ((max > 0) && (fieldValue.trim().length > max))
315
362
  nextErrors.push(`trop long, ${fieldValue.trim().length - max} caractères en trop.`);
316
- if (globals.parameters.debugging) {
363
+ if (this.debugging) {
317
364
  console.log(`pFieldObject.name->`, JSON.stringify(pFieldObject.name));
318
365
  console.log(`nextErrors->`, JSON.stringify(nextErrors));
319
366
  console.log(`-----------`);
@@ -338,7 +385,7 @@ export class DsDynamicForm extends Component {
338
385
  !isNaN(parseFloat(eventObject.event.target.value)))
339
386
  this.setFieldData(eventObject.fieldObject.name, eventObject.event.target.value);
340
387
  else {
341
- if (globals.parameters.debugging)
388
+ if (this.debugging)
342
389
  console.error(`Value rejected -> ${eventObject.event.target.value}`);
343
390
  }
344
391
  this.checkValidation(eventObject.fieldObject);
@@ -385,23 +432,22 @@ export class DsDynamicForm extends Component {
385
432
  };
386
433
  this._rowRendering = (row) => {
387
434
  try {
388
- return (_jsx(ReactstrapRow, { children: row.Cols.map((col, ii) => {
435
+ return (_jsx(FlexRow, { children: row.Cols.map((col, ii) => {
389
436
  return (this._colRendering(col));
390
437
  }) }));
391
438
  }
392
439
  catch (err) {
393
- return (_jsxs(ReactstrapCol, { children: ["Error ", err.message] }));
440
+ return (_jsxs(FlexCol, { children: ["Error ", err.message] }));
394
441
  }
395
442
  };
396
443
  this._colRendering = (col) => {
397
- var _a, _b, _c, _d;
398
444
  try {
399
- return (_jsx(ReactstrapCol, { xs: (_a = this.props.col_xs) !== null && _a !== void 0 ? _a : 12, sm: (_b = this.props.col_sm) !== null && _b !== void 0 ? _b : 12, md: (_c = this.props.col_md) !== null && _c !== void 0 ? _c : 6, lg: (_d = this.props.col_lg) !== null && _d !== void 0 ? _d : 4, id: `${col.Id ? col.Id : ''}`, children: col.Fields.map((field, ii) => {
445
+ return (_jsx(FlexCol, { id: `${col.Id ? col.Id : ''}`, children: col.Fields.map((field, ii) => {
400
446
  return this._fieldRendering(field, ii);
401
447
  }) }));
402
448
  }
403
449
  catch (err) {
404
- return (_jsxs(ReactstrapCol, { children: ["Error ", err.message] }));
450
+ return (_jsxs(FlexCol, { children: ["Error ", err.message] }));
405
451
  }
406
452
  };
407
453
  this._fieldRendering = (field, ii) => {
@@ -421,7 +467,7 @@ export class DsDynamicForm extends Component {
421
467
  /* Checkbox is override with combobox */
422
468
  return (_jsxs("div", { children: [this.getFieldLabelTitle(field), _jsx(Multiselect, { showArrow: true, options: ["Oui", "Non"], isObject: false, displayValue: "key", selectedValues: this.getFieldData(field.name) ? this.getFieldData(field.name).split(";") : [], placeholder: field.placeholder, emptyRecordMsg: "", onSelect: (selectedList, selectedItem) => { this.setFieldData(field.name, selectedList.join(";")); }, onRemove: (selectedList, selectedItem) => { this.setFieldData(field.name, selectedList.join(";")); }, disable: this.props.read_only, singleSelect: true }), this._error_label(field)] }));
423
469
  case "blob":
424
- return (_jsxs(_Fragment, { children: [this.getFieldLabelTitle(field), _jsxs("div", { className: "col-md-10", children: [_jsx(DsBlob, { item_id: field.name, readOnly: this.props.read_only ? this.props.read_only : false, Caption: `${this.getFieldPrompt(field)} ...`, data: this.getFieldData(field.name), uploadPicture: (UploadFile) => { this.setFieldData(field.name, UploadFile.data); this.checkValidation(field); }, pictureStyle: "pic", buttonStyle: "btn btn-secondary", width: field.width ? field.width : undefined, height: field.height ? field.height : undefined, maxWidth: field.maxWidth ? field.maxWidth : undefined, maxHeight: field.maxHeight ? field.maxHeight : undefined, reduceImage: field.reduceImage ? field.reduceImage : undefined }), this._error_label(field)] })] }));
470
+ return (_jsxs(_Fragment, { children: [this.getFieldLabelTitle(field), _jsxs("div", { className: "col-md-10", children: [_jsx(DsBlob, { item_id: field.name, readOnly: this.props.read_only ? this.props.read_only : false, Caption: `${this.getFieldPrompt(field)} ...`, data: this.getFieldData(field.name), uploadPicture: (UploadFile) => { this.setFieldData(field.name, UploadFile.data); this.checkValidation(field); }, pictureStyle: "pic", buttonStyle: "btn btn-secondary", width: field.width ? field.width : undefined, height: field.height ? field.height : undefined, maxWidth: field.max_width ? field.max_width : undefined, maxHeight: field.max_height ? field.max_height : undefined, maxKBytes: field.max_kbytes ? field.max_kbytes : undefined, reduceImage: field.reduceImage ? field.reduceImage : undefined, onErrorHandler: (errorObject) => { this.onBlobErrorLocalHandler(errorObject); }, debugging: this.debugging }), this._error_label(field)] })] }));
425
471
  case "pdf":
426
472
  return (_jsxs(_Fragment, { children: [this.getFieldLabelTitle(field), _jsxs("div", { className: "col-md-10", children: [_jsx(DsPdf, { item_id: field.name, readOnly: this.props.read_only ? this.props.read_only : false, Caption: `${this.getFieldPrompt(field)} ...`, data: this.getFieldData(field.name), uploadPdf: (UploadFile) => { this.setFieldData(field.name, UploadFile.data); this.checkValidation(field); }, pictureStyle: "pic", buttonStyle: "btn btn-secondary" }), this._error_label(field)] })] }));
427
473
  case "email":
@@ -470,44 +516,41 @@ export class DsDynamicForm extends Component {
470
516
  }
471
517
  };
472
518
  this._cancelButton = () => {
473
- var _a, _b, _c, _d;
474
519
  let buttonIsHidden = (this.props.read_only || (this.props.buttons_options && this.props.buttons_options.cancel_button_hidden)) ? true : false;
475
520
  let buttonCaption = (this.props.buttons_options && this.props.buttons_options.cancel_button_caption) ? this.props.buttons_options.cancel_button_caption : "Annuler";
476
521
  if (buttonIsHidden)
477
522
  return (_jsx(_Fragment, {}));
478
523
  else {
479
- return (_jsx(ReactstrapCol, { xs: (_a = this.props.col_xs) !== null && _a !== void 0 ? _a : 12, sm: (_b = this.props.col_sm) !== null && _b !== void 0 ? _b : 12, md: (_c = this.props.col_md) !== null && _c !== void 0 ? _c : 6, lg: (_d = this.props.col_lg) !== null && _d !== void 0 ? _d : 4, children: _jsx(Button, { id: "dsdf_clear_button", block: true, className: "btn-round", color: "danger", outline: true, type: "reset", onClick: () => { this.clearForm(); }, children: buttonCaption }) }));
524
+ return (_jsx(FlexCol, { children: _jsx(Button, { id: "dsdf_clear_button", block: true, className: "btn-round", color: "danger", outline: true, type: "reset", onClick: () => { this.clearForm(); }, children: buttonCaption }) }));
480
525
  }
481
526
  };
482
527
  this._submitButton = () => {
483
- var _a, _b, _c, _d;
484
528
  let buttonIsHidden = (this.props.read_only || (this.props.buttons_options && this.props.buttons_options.submit_button_hidden)) ? true : false;
485
529
  let buttonCaption = (this.props.buttons_options && this.props.buttons_options.submit_button_caption) ? this.props.buttons_options.submit_button_caption : "Soumettre";
486
530
  if (buttonIsHidden)
487
531
  return (_jsx(_Fragment, {}));
488
532
  else {
489
- return (_jsx(ReactstrapCol, { xs: (_a = this.props.col_xs) !== null && _a !== void 0 ? _a : 12, sm: (_b = this.props.col_sm) !== null && _b !== void 0 ? _b : 12, md: (_c = this.props.col_md) !== null && _c !== void 0 ? _c : 6, lg: (_d = this.props.col_lg) !== null && _d !== void 0 ? _d : 4, children: _jsx(Button, { id: "dsdf_submit_button", block: true, className: "btn-round", color: "danger", outline: true, type: "submit", onClick: () => { this.onClickSubmitFormHandler(); }, children: buttonCaption }) }));
533
+ return (_jsx(FlexCol, { children: _jsx(Button, { id: "dsdf_submit_button", block: true, className: "btn-round", color: "danger", outline: true, type: "submit", onClick: () => { this.onClickSubmitFormHandler(); }, children: buttonCaption }) }));
490
534
  }
491
535
  };
492
536
  this.render = () => {
493
- var _a, _b, _c, _d, _e, _f, _g, _h;
494
537
  return (_jsxs(_Fragment, { children: [_jsx(_Fragment, {}), !this.state.form &&
495
538
  _jsx("div", { children: _jsx("h1", { children: "Form loading..." }) }), !(this.state.form &&
496
539
  this.state.form.Pages) &&
497
540
  _jsx("div", { children: _jsx("h1", { children: "Form Missing Pages !!!" }) }), _jsx("form", { children: this.state.form &&
498
541
  this.state.form.Pages &&
499
542
  this.state.form.Pages.map((page, pageIndex) => {
500
- if (globals.parameters.debugging)
543
+ if (this.debugging)
501
544
  console.log(`Rendering page ${pageIndex}:`, page);
502
545
  return (_jsx("div", { id: `dsdf_page_${pageIndex}`, className: `form-page ${((pageIndex == this.state.active_page) || this.props.read_only) ? "page_visible" : ""}`, children: page.Rows.map((row, rowIndex) => {
503
546
  return (_jsx("div", { children: this._rowRendering(row) }, rowIndex));
504
547
  }) }, pageIndex));
505
- }) }), _jsxs(ReactstrapRow, { id: "dsdf_buttons_container", className: "buttons-row", children: [this._cancelButton(), this._submitButton(), this.props.custom_button_caption &&
506
- _jsx(ReactstrapCol, { xs: (_a = this.props.col_xs) !== null && _a !== void 0 ? _a : 12, sm: (_b = this.props.col_sm) !== null && _b !== void 0 ? _b : 12, md: (_c = this.props.col_md) !== null && _c !== void 0 ? _c : 6, lg: (_d = this.props.col_lg) !== null && _d !== void 0 ? _d : 4, children: _jsx(Button, { id: "dsdf_custom_button", block: true, className: "btn-round", color: "primary", type: "submit", onClick: (e) => { if (this.props.custom_button_handler)
548
+ }) }), _jsxs(FlexRow, { id: "dsdf_buttons_container", className: "buttons-row", children: [this._cancelButton(), this._submitButton(), this.props.custom_button_caption &&
549
+ _jsx(FlexCol, { children: _jsx(Button, { id: "dsdf_custom_button", block: true, className: "btn-round", color: "primary", type: "submit", onClick: (e) => { if (this.props.custom_button_handler)
507
550
  this.props.custom_button_handler(this.state.form);
508
551
  else
509
552
  console.error("custom_button_handler unset !"); }, children: this.props.custom_button_caption }) }), this.props.custom_button_caption2 &&
510
- _jsx(ReactstrapCol, { xs: (_e = this.props.col_xs) !== null && _e !== void 0 ? _e : 12, sm: (_f = this.props.col_sm) !== null && _f !== void 0 ? _f : 12, md: (_g = this.props.col_md) !== null && _g !== void 0 ? _g : 6, lg: (_h = this.props.col_lg) !== null && _h !== void 0 ? _h : 4, children: _jsx(Button, { id: "dsdf_custom_button2", block: true, className: "btn-round", color: "primary", type: "submit", onClick: (e) => { if (this.props.custom_button_handler2)
553
+ _jsx(FlexCol, { children: _jsx(Button, { id: "dsdf_custom_button2", block: true, className: "btn-round", color: "primary", type: "submit", onClick: (e) => { if (this.props.custom_button_handler2)
511
554
  this.props.custom_button_handler2(this.state.form);
512
555
  else
513
556
  console.error("custom_button_handler2 unset !"); }, children: this.props.custom_button_caption2 }) })] })] }));
@@ -515,6 +558,10 @@ export class DsDynamicForm extends Component {
515
558
  this.state = { form: { Pages: [] }, active_page: 0 };
516
559
  this.local_data_blob = { data_tier: {} };
517
560
  }
561
+ // Helper method to get debugging value from props with default fallback
562
+ get debugging() {
563
+ return this.props.debugging ?? false;
564
+ }
518
565
  componentDidUpdate(prevProps) {
519
566
  // Typical usage (don't forget to compare props):
520
567
  if (this.props.form !== prevProps.form) {
@@ -526,7 +573,10 @@ export class DsDynamicForm extends Component {
526
573
  this.clearForm();
527
574
  }
528
575
  if (this.props.active_page != prevProps.active_page) {
529
- if (globals.parameters.debugging)
576
+ //Page is about to change, then triger onPageChanging Handler
577
+ if (this.props.onPageChanging)
578
+ this.props.onPageChanging({ "active_page": prevProps.active_page ?? 0, "next_page": this.props.active_page ?? 0, "last_page": this.state.form.Pages.length - 1 });
579
+ if (this.debugging)
530
580
  console.log("active_page has changed !");
531
581
  try {
532
582
  if (prevProps.active_page !== undefined) {
@@ -552,14 +602,18 @@ export const DsDynamicFormForwardRef = forwardRef((props, ref) => {
552
602
  const innerRef = React.useRef(null);
553
603
  useImperativeHandle(ref, () => ({
554
604
  clearForm: () => {
555
- var _a;
556
- (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.clearForm();
605
+ innerRef.current?.clearForm();
557
606
  },
558
607
  onClickSubmitFormHandler: (event) => {
559
608
  return innerRef.current
560
609
  ? innerRef.current.onClickSubmitFormHandler(event)
561
610
  : Promise.resolve(false);
562
611
  },
612
+ checkCurrentPage: (event) => {
613
+ return innerRef.current
614
+ ? innerRef.current.checkCurrentPage(event)
615
+ : Promise.resolve(false);
616
+ },
563
617
  }));
564
- return (_jsx(DsDynamicForm, Object.assign({}, props, { ref: innerRef })));
618
+ return (_jsx(DsDynamicForm, { ...props, ref: innerRef }));
565
619
  });
@@ -0,0 +1,51 @@
1
+ .flex-row {
2
+ display: flex;
3
+ flex-wrap: wrap;
4
+ gap: 10px;
5
+ margin-bottom: 10px;
6
+ /* Make all .flex-col in a flex-row equal height */
7
+ align-items: stretch;
8
+ /* For multi-line rows, ensure lines use full vertical space */
9
+ align-content: stretch;
10
+ }
11
+
12
+ .flex-col {
13
+ flex: 1 1 0;
14
+ /* Fill available vertical space of its flex line */
15
+ height: 100%;
16
+ min-height: 100px;
17
+ border: 3px solid;
18
+ border-radius: 8px;
19
+ display: flex;
20
+ align-items: center;
21
+ justify-content: center;
22
+ }
23
+
24
+ .box-next {
25
+ flex: 1 1 0;
26
+ display: flex;
27
+ flex-wrap: wrap;
28
+ align-content: center;
29
+ }
30
+
31
+ /* Media query pour 600px : diviser par 2 le nombre de div par ligne */
32
+ @media (max-width: 600px) {
33
+ .box {
34
+ flex: 1 1 calc(50% - 5px);
35
+ max-width: calc(50% - 5px);
36
+ }
37
+
38
+ /* Si une div est seule sur sa ligne, elle prend 100% */
39
+ .box:only-child {
40
+ flex: 1 1 100%;
41
+ max-width: 100%;
42
+ }
43
+ }
44
+
45
+ /* Media query pour 300px : toutes les divs à 100% de la largeur */
46
+ @media (max-width: 300px) {
47
+ .box {
48
+ flex: 1 1 100%;
49
+ max-width: 100%;
50
+ }
51
+ }
@@ -1,4 +1,5 @@
1
1
  import React, { Component, ChangeEvent } from "react";
2
+ import "./flex-grid.css";
2
3
  interface Field {
3
4
  name: string;
4
5
  input_type: string;
@@ -12,8 +13,9 @@ interface Field {
12
13
  hidden?: boolean;
13
14
  width?: number;
14
15
  height?: number;
15
- maxWidth?: number;
16
- maxHeight?: number;
16
+ max_width?: number;
17
+ max_height?: number;
18
+ max_kbytes?: number;
17
19
  reduceImage?: boolean;
18
20
  name_day?: string;
19
21
  name_month?: string;
@@ -79,10 +81,17 @@ interface DsDynamicFormProps {
79
81
  read_only?: boolean;
80
82
  foreign_keys?: DataTier;
81
83
  onFormChange?: (data: DataTier) => void;
84
+ onBeforeFormSubmit?: (data: DataBlob) => void;
82
85
  onFormSubmit?: (data: DataBlob) => void;
83
86
  onFormSaved?: (blob: DataBlob) => void;
84
87
  onFormUpdated?: (blob: DataBlob) => void;
85
88
  onFormFailed?: (error: string) => void;
89
+ onPageChanging?: (pageInfo: {
90
+ active_page: number;
91
+ next_page: number;
92
+ last_page: number;
93
+ }) => void;
94
+ onBlobErrorHandler?: (errorObject: ErrorObject) => void;
86
95
  clearOnSave?: boolean;
87
96
  clearOnUpdate?: boolean;
88
97
  onTerminated?: () => void;
@@ -101,6 +110,7 @@ interface DsDynamicFormProps {
101
110
  col_sm?: number | string;
102
111
  col_md?: number | string;
103
112
  col_lg?: number | string;
113
+ debugging?: boolean;
104
114
  }
105
115
  interface DsDynamicFormState {
106
116
  form: Form;
@@ -111,9 +121,15 @@ interface DsDynamicFormState {
111
121
  captcha2?: number;
112
122
  active_page?: number;
113
123
  }
124
+ interface ErrorObject {
125
+ error_code: string;
126
+ error_definition: string;
127
+ message: string;
128
+ }
114
129
  export declare class DsDynamicForm extends Component<DsDynamicFormProps, DsDynamicFormState> {
115
130
  private local_data_blob;
116
131
  constructor(props: DsDynamicFormProps);
132
+ private get debugging();
117
133
  componentDidMount: () => void;
118
134
  componentDidUpdate(prevProps: DsDynamicFormProps): void;
119
135
  /**
@@ -144,9 +160,11 @@ export declare class DsDynamicForm extends Component<DsDynamicFormProps, DsDynam
144
160
  saveFormToDatasyncProcess: () => void;
145
161
  /** Form Handlers */
146
162
  onClickSubmitFormHandler: (event?: React.MouseEvent<HTMLButtonElement>) => Promise<boolean>;
163
+ checkCurrentPage: (event?: React.MouseEvent<HTMLButtonElement>) => Promise<boolean>;
147
164
  onFormSavedLocalHandler: (blob: DataBlob) => void;
148
165
  onFormUpdatedLocalHandler: (blob: DataBlob) => void;
149
166
  onFormFailedLocalHandler: (err: string) => void;
167
+ onBlobErrorLocalHandler: (errorObject: ErrorObject) => void;
150
168
  checkValidation: (pFieldObject: Field) => boolean;
151
169
  dynamicInputTextChangeHandler: (eventObject: EventObject) => void;
152
170
  dynamicInputNumericChangeHandler: (eventObject: EventObject) => void;
@@ -167,6 +185,7 @@ export declare class DsDynamicForm extends Component<DsDynamicFormProps, DsDynam
167
185
  export type DsDynamicFormRef = {
168
186
  clearForm: () => void;
169
187
  onClickSubmitFormHandler: (event?: React.MouseEvent<HTMLButtonElement>) => Promise<boolean>;
188
+ checkCurrentPage: (event?: React.MouseEvent<HTMLButtonElement>) => Promise<boolean>;
170
189
  };
171
- export declare const DsDynamicFormForwardRef: any;
190
+ export declare const DsDynamicFormForwardRef: React.ForwardRefExoticComponent<DsDynamicFormProps & React.RefAttributes<DsDynamicFormRef>>;
172
191
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "datasync-dynamic-form",
3
3
  "description": "Datasync Dynamic Form component",
4
- "version": "1.3.4",
4
+ "version": "1.3.6",
5
5
  "main": "dist/DsDynamicForm.js",
6
6
  "module": "dist/DsDynamicForm.js",
7
7
  "types": "dist/types/DsDynamicForm.d.ts",
@@ -17,6 +17,8 @@
17
17
  "email": "pmabiala@me.com"
18
18
  },
19
19
  "devDependencies": {
20
+ "@types/react": "^18.2.75",
21
+ "@types/react-dom": "^18.2.25",
20
22
  "datasync-core": "^1.0.44",
21
23
  "multiselect-react-dropdown": "^2.0.25",
22
24
  "react": ">=18.2.0",
@@ -28,14 +30,14 @@
28
30
  "react": "^17 || ^18"
29
31
  },
30
32
  "scripts": {
31
- "hybrid": "tsc"
33
+ "hybrid": "tsc && cp src/flex-grid.css dist/flex-grid.css"
32
34
  },
33
35
  "keywords": [],
34
36
  "author": "",
35
37
  "license": "ISC",
36
38
  "dependencies": {
37
39
  "axios": "^1.7.2",
38
- "datasync-blob": "^1.1.10",
40
+ "datasync-blob": "^1.1.12",
39
41
  "datasync-pdf": "^0.0.1",
40
42
  "runscripts": "^0.0.1"
41
43
  }