datasync-dynamic-form 1.1.23 → 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.
- package/dist/DsDynamicForm.js +54 -26
- package/dist/types/DsDynamicForm.d.ts +9 -1
- package/package.json +1 -1
package/dist/DsDynamicForm.js
CHANGED
|
@@ -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: {
|
|
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 || {
|
|
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
|
|
181
|
-
while ((
|
|
190
|
+
let iPage = 0;
|
|
191
|
+
while ((iPage < this.state.form.Pages.length)
|
|
182
192
|
&& (canSubmit)) {
|
|
183
|
-
let
|
|
184
|
-
while ((
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
205
|
+
iRow++;
|
|
191
206
|
}
|
|
192
|
-
|
|
207
|
+
iPage++;
|
|
193
208
|
}
|
|
194
209
|
if (!canSubmit) {
|
|
195
210
|
let err_message = "Le formulaire comporte des erreurs !";
|
|
@@ -364,7 +379,7 @@ export class DsDynamicForm extends Component {
|
|
|
364
379
|
};
|
|
365
380
|
this._colRendering = (col) => {
|
|
366
381
|
try {
|
|
367
|
-
return (_jsx(ReactstrapCol, { children: col.Fields.map((field, ii) => {
|
|
382
|
+
return (_jsx(ReactstrapCol, { id: `${col.Id ? col.Id : ''}`, children: col.Fields.map((field, ii) => {
|
|
368
383
|
return this._fieldRendering(field, ii);
|
|
369
384
|
}) }));
|
|
370
385
|
}
|
|
@@ -441,7 +456,7 @@ export class DsDynamicForm extends Component {
|
|
|
441
456
|
if (buttonIsHidden)
|
|
442
457
|
return (_jsx(_Fragment, {}));
|
|
443
458
|
else {
|
|
444
|
-
return (_jsx(ReactstrapCol, { md: "4", sm: "4", children: _jsx(Button, { block: true, className: "btn-round", color: "danger", outline: true, type: "reset", onClick: () => { this.clearForm(); }, children: buttonCaption }) }));
|
|
459
|
+
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 }) }));
|
|
445
460
|
}
|
|
446
461
|
};
|
|
447
462
|
this._submitButton = () => {
|
|
@@ -450,30 +465,29 @@ export class DsDynamicForm extends Component {
|
|
|
450
465
|
if (buttonIsHidden)
|
|
451
466
|
return (_jsx(_Fragment, {}));
|
|
452
467
|
else {
|
|
453
|
-
return (_jsx(ReactstrapCol, { md: "4", sm: "4", children: _jsx(Button, { block: true, className: "btn-round", color: "danger", outline: true, type: "submit", onClick: () => { this.onClickSubmitFormHandler(); }, children: buttonCaption }) }));
|
|
468
|
+
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 }) }));
|
|
454
469
|
}
|
|
455
470
|
};
|
|
456
471
|
this.render = () => {
|
|
457
472
|
return (_jsxs(_Fragment, { children: [!this.state.form &&
|
|
458
473
|
_jsx("div", { children: _jsx("h1", { children: "Form loading..." }) }), _jsx("form", { children: this.state.form &&
|
|
459
|
-
this.state.form.
|
|
460
|
-
this.state.form.
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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));
|
|
480
|
+
}) }), _jsxs(ReactstrapRow, { id: "dsdf_buttons_container", className: "buttons-row", children: [this._cancelButton(), this._submitButton(), this.props.custom_button_caption &&
|
|
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)
|
|
464
482
|
this.props.custom_button_handler(this.state.form);
|
|
465
483
|
else
|
|
466
484
|
console.error("custom_button_handler unset !"); }, children: this.props.custom_button_caption }) }), this.props.custom_button_caption2 &&
|
|
467
|
-
_jsx(ReactstrapCol, { md: "4", sm: "4", children: _jsx(Button, { block: true, className: "btn-round", color: "primary", type: "submit", onClick: (e) => { if (this.props.custom_button_handler2)
|
|
485
|
+
_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)
|
|
468
486
|
this.props.custom_button_handler2(this.state.form);
|
|
469
487
|
else
|
|
470
488
|
console.error("custom_button_handler2 unset !"); }, children: this.props.custom_button_caption2 }) })] })] }));
|
|
471
489
|
};
|
|
472
|
-
|
|
473
|
-
console.log("30:DynamicForm3Tiers2::this.props.data_blob", this.props.data_blob);
|
|
474
|
-
console.log("30DynamicForm3Tiers::this.props.form", this.props.form);
|
|
475
|
-
}
|
|
476
|
-
this.state = { form: { Rows: [] } };
|
|
490
|
+
this.state = { form: { Pages: [] }, active_page: 0 };
|
|
477
491
|
this.local_data_blob = { data_tier: {} };
|
|
478
492
|
}
|
|
479
493
|
componentDidUpdate(prevProps) {
|
|
@@ -486,5 +500,19 @@ export class DsDynamicForm extends Component {
|
|
|
486
500
|
//Lookup field props has changed
|
|
487
501
|
this.clearForm();
|
|
488
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
|
+
}
|
|
489
517
|
}
|
|
490
518
|
}
|
|
@@ -22,14 +22,18 @@ interface Field {
|
|
|
22
22
|
name_min?: string;
|
|
23
23
|
}
|
|
24
24
|
interface Col {
|
|
25
|
+
Id: string;
|
|
25
26
|
Fields: Field[];
|
|
26
27
|
}
|
|
27
28
|
interface Row {
|
|
28
29
|
Cols: Col[];
|
|
29
30
|
}
|
|
30
|
-
interface
|
|
31
|
+
interface Page {
|
|
31
32
|
Rows: Row[];
|
|
32
33
|
}
|
|
34
|
+
interface Form {
|
|
35
|
+
Pages: Page[];
|
|
36
|
+
}
|
|
33
37
|
interface DataTier {
|
|
34
38
|
[key: string]: any;
|
|
35
39
|
}
|
|
@@ -106,6 +110,10 @@ export declare class DsDynamicForm extends Component<DsDynamicFormProps, DsDynam
|
|
|
106
110
|
constructor(props: DsDynamicFormProps);
|
|
107
111
|
componentDidMount: () => void;
|
|
108
112
|
componentDidUpdate(prevProps: DsDynamicFormProps): void;
|
|
113
|
+
/**
|
|
114
|
+
* Prototype : updateElement
|
|
115
|
+
*/
|
|
116
|
+
updatePageDomElement: (p_pageIndex: any, p_page_isVisible: any) => void;
|
|
109
117
|
/**
|
|
110
118
|
* Prototype : clearForm
|
|
111
119
|
*/
|
package/package.json
CHANGED