datasync-dynamic-form 1.1.24 → 1.1.25

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.
@@ -37,13 +37,23 @@ export class DsDynamicForm extends Component {
37
37
  this.clearForm();
38
38
  }
39
39
  };
40
+ /**
41
+ * Prototype : updateElement
42
+ */
43
+ this.updatePageDomElement = (p_pageIndex, p_page_isVisible) => {
44
+ let pageObject = document.getElementById(`dsdf_page_${p_pageIndex}`);
45
+ if (p_page_isVisible)
46
+ pageObject.classList.add("page_visible");
47
+ else
48
+ pageObject.classList.remove("page_visible");
49
+ };
40
50
  /**
41
51
  * Prototype : clearForm
42
52
  */
43
53
  this.clearForm = () => {
44
- this.setState({ fieldError: {}, form: { Rows: [] }, captcha1: Randomize(0, 5), captcha2: Randomize(0, 5) }, //Clear forced
54
+ this.setState({ fieldError: {}, form: { Pages: [] }, captcha1: Randomize(0, 5), captcha2: Randomize(0, 5) }, //Clear forced
45
55
  () => {
46
- this.setState({ form: this.props.form || { Rows: [] }, fieldError: {} }); //No need to override form property with clearObject2 anymore because data are written outside form.
56
+ this.setState({ form: this.props.form || { Pages: [] }, fieldError: {} }); //No need to override form property with clearObject2 anymore because data are written outside form.
47
57
  });
48
58
  //Real efficient fix
49
59
  let duplicate_data_tier = (this.props.data_blob && this.props.data_blob.data_tier) ? JSON.parse(JSON.stringify(this.props.data_blob.data_tier)) : {};
@@ -177,19 +187,24 @@ export class DsDynamicForm extends Component {
177
187
  event.preventDefault();
178
188
  //Force all fields check
179
189
  let canSubmit = true;
180
- let iRow = 0;
181
- while ((iRow < this.state.form.Rows.length)
190
+ let iPage = 0;
191
+ while ((iPage < this.state.form.Pages.length)
182
192
  && (canSubmit)) {
183
- let iCol = 0;
184
- while ((iCol < this.state.form.Rows[iRow].Cols.length) && canSubmit) {
185
- let ii = 0;
186
- while ((ii < this.state.form.Rows[iRow].Cols[iCol].Fields.length)
187
- && (canSubmit && (canSubmit = this.checkValidation(this.state.form.Rows[iRow].Cols[iCol].Fields[ii])))) {
188
- ii++;
193
+ let iRow = 0;
194
+ while ((iRow < this.state.form.Pages[iPage].Rows.length)
195
+ && (canSubmit)) {
196
+ let iCol = 0;
197
+ while ((iCol < this.state.form.Pages[iPage].Rows[iRow].Cols.length) && canSubmit) {
198
+ let ii = 0;
199
+ while ((ii < this.state.form.Pages[iPage].Rows[iRow].Cols[iCol].Fields.length)
200
+ && (canSubmit && (canSubmit = this.checkValidation(this.state.form.Pages[iPage].Rows[iRow].Cols[iCol].Fields[ii])))) {
201
+ ii++;
202
+ }
203
+ iCol++;
189
204
  }
190
- iCol++;
205
+ iRow++;
191
206
  }
192
- iRow++;
207
+ iPage++;
193
208
  }
194
209
  if (!canSubmit) {
195
210
  let err_message = "Le formulaire comporte des erreurs !";
@@ -364,7 +379,6 @@ export class DsDynamicForm extends Component {
364
379
  };
365
380
  this._colRendering = (col) => {
366
381
  try {
367
- console.log("col-->", col);
368
382
  return (_jsx(ReactstrapCol, { id: `${col.Id ? col.Id : ''}`, children: col.Fields.map((field, ii) => {
369
383
  return this._fieldRendering(field, ii);
370
384
  }) }));
@@ -457,9 +471,12 @@ export class DsDynamicForm extends Component {
457
471
  this.render = () => {
458
472
  return (_jsxs(_Fragment, { children: [!this.state.form &&
459
473
  _jsx("div", { children: _jsx("h1", { children: "Form loading..." }) }), _jsx("form", { children: this.state.form &&
460
- this.state.form.Rows &&
461
- this.state.form.Rows.map(row => {
462
- return (this._rowRendering(row));
474
+ this.state.form.Pages &&
475
+ this.state.form.Pages.map((page, pageIndex) => {
476
+ console.log(`Rendering page ${pageIndex}:`, page);
477
+ return (_jsx("div", { id: `dsdf_page_${pageIndex}`, className: `form-page ${pageIndex == this.state.active_page ? "page_visible" : ""}`, children: page.Rows.map((row, rowIndex) => {
478
+ return (_jsx("div", { children: this._rowRendering(row) }, rowIndex));
479
+ }) }, pageIndex));
463
480
  }) }), _jsxs(ReactstrapRow, { id: "dsdf_buttons_container", className: "buttons-row", children: [this._cancelButton(), this._submitButton(), this.props.custom_button_caption &&
464
481
  _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)
465
482
  this.props.custom_button_handler(this.state.form);
@@ -470,11 +487,7 @@ export class DsDynamicForm extends Component {
470
487
  else
471
488
  console.error("custom_button_handler2 unset !"); }, children: this.props.custom_button_caption2 }) })] })] }));
472
489
  };
473
- if (globals.parameters.debugging) {
474
- console.log("30:DynamicForm3Tiers2::this.props.data_blob", this.props.data_blob);
475
- console.log("30DynamicForm3Tiers::this.props.form", this.props.form);
476
- }
477
- this.state = { form: { Rows: [] } };
490
+ this.state = { form: { Pages: [] }, active_page: 0 };
478
491
  this.local_data_blob = { data_tier: {} };
479
492
  }
480
493
  componentDidUpdate(prevProps) {
@@ -487,5 +500,19 @@ export class DsDynamicForm extends Component {
487
500
  //Lookup field props has changed
488
501
  this.clearForm();
489
502
  }
503
+ if (this.props.active_page != prevProps.active_page) {
504
+ try {
505
+ this.updatePageDomElement(this.prevProps.active_page, false);
506
+ }
507
+ catch (error) {
508
+ this.updatePageDomElement(0, false);
509
+ }
510
+ try {
511
+ this.updatePageDomElement(this.props.active_page, true);
512
+ }
513
+ catch (error) {
514
+ this.updatePageDomElement(1, true);
515
+ }
516
+ }
490
517
  }
491
518
  }
@@ -28,9 +28,12 @@ interface Col {
28
28
  interface Row {
29
29
  Cols: Col[];
30
30
  }
31
- interface Form {
31
+ interface Page {
32
32
  Rows: Row[];
33
33
  }
34
+ interface Form {
35
+ Pages: Page[];
36
+ }
34
37
  interface DataTier {
35
38
  [key: string]: any;
36
39
  }
@@ -107,6 +110,10 @@ export declare class DsDynamicForm extends Component<DsDynamicFormProps, DsDynam
107
110
  constructor(props: DsDynamicFormProps);
108
111
  componentDidMount: () => void;
109
112
  componentDidUpdate(prevProps: DsDynamicFormProps): void;
113
+ /**
114
+ * Prototype : updateElement
115
+ */
116
+ updatePageDomElement: (p_pageIndex: any, p_page_isVisible: any) => void;
110
117
  /**
111
118
  * Prototype : clearForm
112
119
  */
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.1.24",
4
+ "version": "1.1.25",
5
5
  "main": "dist/DsDynamicForm.js",
6
6
  "module": "dist/DsDynamicForm.js",
7
7
  "types": "dist/types/DsDynamicForm.d.ts",