datasync-dynamic-form 1.3.0 → 1.3.3

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.
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
- import React, { Component } from "react";
11
+ import React, { Component, useImperativeHandle, forwardRef } from "react";
12
12
  import Multiselect from 'multiselect-react-dropdown';
13
13
  import { CTimeStamp, Randomize, SaveDataTierToDatasync, WScrollTo } from "datasync-core";
14
14
  import { DsBlob } from "datasync-blob";
@@ -16,13 +16,10 @@ import { DsPdf } from "datasync-pdf";
16
16
  // reactstrap components
17
17
  import { Button, Label, FormGroup, Input, InputGroupText, InputGroup, Row as ReactstrapRow, Col as ReactstrapCol, } from "reactstrap";
18
18
  const debugging = false;
19
- const local = true;
20
- const production = !local;
21
19
  const globals = {
22
20
  parameters: {
23
21
  debugging: debugging,
24
22
  local: true,
25
- production: false,
26
23
  use_navigate: false,
27
24
  save_failed_alert: false,
28
25
  form_version: "1.0",
@@ -104,8 +101,6 @@ export class DsDynamicForm extends Component {
104
101
  let nextFieldError = this.state.fieldError || {};
105
102
  nextFieldError[pFieldObject.name] = value;
106
103
  this.setState({ fieldError: nextFieldError });
107
- //Scroll form to first erroneous field
108
- WScrollTo(pFieldObject.name);
109
104
  }
110
105
  catch (e) {
111
106
  console.error(`Error caught on ${e}`);
@@ -198,17 +193,21 @@ export class DsDynamicForm extends Component {
198
193
  event.preventDefault();
199
194
  //Force all fields check
200
195
  let canSubmit = true;
196
+ let firstErrFieldName = null;
201
197
  let iPage = 0;
202
- while ((iPage < this.state.form.Pages.length)
203
- && (canSubmit)) {
198
+ while (iPage < this.state.form.Pages.length) {
204
199
  let iRow = 0;
205
- while ((iRow < this.state.form.Pages[iPage].Rows.length)
206
- && (canSubmit)) {
200
+ while (iRow < this.state.form.Pages[iPage].Rows.length) {
207
201
  let iCol = 0;
208
- while ((iCol < this.state.form.Pages[iPage].Rows[iRow].Cols.length) && canSubmit) {
202
+ while (iCol < this.state.form.Pages[iPage].Rows[iRow].Cols.length) {
209
203
  let ii = 0;
210
- while ((ii < this.state.form.Pages[iPage].Rows[iRow].Cols[iCol].Fields.length)
211
- && (canSubmit && (canSubmit = this.checkValidation(this.state.form.Pages[iPage].Rows[iRow].Cols[iCol].Fields[ii])))) {
204
+ while (ii < this.state.form.Pages[iPage].Rows[iRow].Cols[iCol].Fields.length) {
205
+ const field = this.state.form.Pages[iPage].Rows[iRow].Cols[iCol].Fields[ii];
206
+ const isValid = this.checkValidation(field);
207
+ if (!isValid && firstErrFieldName === null) {
208
+ firstErrFieldName = field.name;
209
+ }
210
+ canSubmit = canSubmit && isValid;
212
211
  ii++;
213
212
  }
214
213
  iCol++;
@@ -218,6 +217,12 @@ export class DsDynamicForm extends Component {
218
217
  iPage++;
219
218
  }
220
219
  if (!canSubmit) {
220
+ // Scroll to the first field with error only on submit
221
+ if (firstErrFieldName) {
222
+ if (globals.parameters.debugging)
223
+ console.log("WScrollTo invoked :-)");
224
+ WScrollTo(firstErrFieldName);
225
+ }
221
226
  let err_message = "Le formulaire comporte des erreurs !";
222
227
  if (this.props.onFormFailed)
223
228
  this.props.onFormFailed(err_message);
@@ -390,7 +395,7 @@ export class DsDynamicForm extends Component {
390
395
  };
391
396
  this._colRendering = (col) => {
392
397
  try {
393
- return (_jsx(ReactstrapCol, { id: `${col.Id ? col.Id : ''}`, children: col.Fields.map((field, ii) => {
398
+ return (_jsx(ReactstrapCol, { xs: "12", sm: "12", md: "6", lg: "4", id: `${col.Id ? col.Id : ''}`, children: col.Fields.map((field, ii) => {
394
399
  return this._fieldRendering(field, ii);
395
400
  }) }));
396
401
  }
@@ -469,7 +474,7 @@ export class DsDynamicForm extends Component {
469
474
  if (buttonIsHidden)
470
475
  return (_jsx(_Fragment, {}));
471
476
  else {
472
- return (_jsx(ReactstrapCol, { md: "4", sm: "4", children: _jsx(Button, { id: "dsdf_clear_button", block: true, className: "btn-round", color: "danger", outline: true, type: "reset", onClick: () => { this.clearForm(); }, children: buttonCaption }) }));
477
+ return (_jsx(ReactstrapCol, { xs: "12", sm: "12", md: "6", lg: "4", children: _jsx(Button, { id: "dsdf_clear_button", block: true, className: "btn-round", color: "danger", outline: true, type: "reset", onClick: () => { this.clearForm(); }, children: buttonCaption }) }));
473
478
  }
474
479
  };
475
480
  this._submitButton = () => {
@@ -478,11 +483,11 @@ export class DsDynamicForm extends Component {
478
483
  if (buttonIsHidden)
479
484
  return (_jsx(_Fragment, {}));
480
485
  else {
481
- return (_jsx(ReactstrapCol, { md: "4", sm: "4", children: _jsx(Button, { id: "dsdf_submit_button", block: true, className: "btn-round", color: "danger", outline: true, type: "submit", onClick: () => { this.onClickSubmitFormHandler(); }, children: buttonCaption }) }));
486
+ return (_jsx(ReactstrapCol, { xs: "12", sm: "12", md: "6", lg: "4", children: _jsx(Button, { id: "dsdf_submit_button", block: true, className: "btn-round", color: "danger", outline: true, type: "submit", onClick: () => { this.onClickSubmitFormHandler(); }, children: buttonCaption }) }));
482
487
  }
483
488
  };
484
489
  this.render = () => {
485
- return (_jsxs(_Fragment, { children: [_jsx(_Fragment, { children: console.log('form->', this.props.form) }), !this.state.form &&
490
+ return (_jsxs(_Fragment, { children: [_jsx(_Fragment, {}), !this.state.form &&
486
491
  _jsx("div", { children: _jsx("h1", { children: "Form loading..." }) }), !(this.state.form &&
487
492
  this.state.form.Pages) &&
488
493
  _jsx("div", { children: _jsx("h1", { children: "Form Missing Pages !!!" }) }), _jsx("form", { children: this.state.form &&
@@ -494,11 +499,11 @@ export class DsDynamicForm extends Component {
494
499
  return (_jsx("div", { children: this._rowRendering(row) }, rowIndex));
495
500
  }) }, pageIndex));
496
501
  }) }), _jsxs(ReactstrapRow, { id: "dsdf_buttons_container", className: "buttons-row", children: [this._cancelButton(), this._submitButton(), this.props.custom_button_caption &&
497
- _jsx(ReactstrapCol, { md: "4", sm: "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)
502
+ _jsx(ReactstrapCol, { xs: "12", sm: "12", md: "6", lg: "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)
498
503
  this.props.custom_button_handler(this.state.form);
499
504
  else
500
505
  console.error("custom_button_handler unset !"); }, children: this.props.custom_button_caption }) }), this.props.custom_button_caption2 &&
501
- _jsx(ReactstrapCol, { md: "4", sm: "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)
506
+ _jsx(ReactstrapCol, { xs: "12", sm: "12", md: "6", lg: "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)
502
507
  this.props.custom_button_handler2(this.state.form);
503
508
  else
504
509
  console.error("custom_button_handler2 unset !"); }, children: this.props.custom_button_caption2 }) })] })] }));
@@ -538,3 +543,19 @@ export class DsDynamicForm extends Component {
538
543
  }
539
544
  }
540
545
  }
546
+ // ForwardRef wrapper that exposes only the desired methods
547
+ export const DsDynamicFormForwardRef = forwardRef((props, ref) => {
548
+ const innerRef = React.useRef(null);
549
+ useImperativeHandle(ref, () => ({
550
+ clearForm: () => {
551
+ var _a;
552
+ (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.clearForm();
553
+ },
554
+ onClickSubmitFormHandler: (event) => {
555
+ return innerRef.current
556
+ ? innerRef.current.onClickSubmitFormHandler(event)
557
+ : Promise.resolve(false);
558
+ },
559
+ }));
560
+ return (_jsx(DsDynamicForm, Object.assign({}, props, { ref: innerRef })));
561
+ });
@@ -160,4 +160,9 @@ export declare class DsDynamicForm extends Component<DsDynamicFormProps, DsDynam
160
160
  _submitButton: () => JSX.Element;
161
161
  render: () => JSX.Element;
162
162
  }
163
+ export type DsDynamicFormRef = {
164
+ clearForm: () => void;
165
+ onClickSubmitFormHandler: (event?: React.MouseEvent<HTMLButtonElement>) => Promise<boolean>;
166
+ };
167
+ export declare const DsDynamicFormForwardRef: any;
163
168
  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.0",
4
+ "version": "1.3.3",
5
5
  "main": "dist/DsDynamicForm.js",
6
6
  "module": "dist/DsDynamicForm.js",
7
7
  "types": "dist/types/DsDynamicForm.d.ts",
@@ -35,7 +35,8 @@
35
35
  "license": "ISC",
36
36
  "dependencies": {
37
37
  "axios": "^1.7.2",
38
- "datasync-blob": "^1.1.7",
39
- "datasync-pdf": "^0.0.1"
38
+ "datasync-blob": "^1.1.10",
39
+ "datasync-pdf": "^0.0.1",
40
+ "runscripts": "^0.0.1"
40
41
  }
41
42
  }