@5minds/node-red-dashboard-2-processcube-dynamic-form 2.4.0-develop-eade06-mfgp8vwu → 2.4.1-develop-f857c6-mfnkln97

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.
@@ -216,6 +216,21 @@ function requiredIf({ value }, [targetField, expectedValue], node) {
216
216
  return true;
217
217
  }
218
218
 
219
+ function normalizeCustomForm(input, defaultValue = {}) {
220
+ if (typeof input === "string") {
221
+ try {
222
+ return JSON.parse(input);
223
+ } catch {
224
+ return defaultValue;
225
+ }
226
+ }
227
+ if (typeof input === "object" && input !== null) {
228
+ return { ...input };
229
+ }
230
+ return defaultValue;
231
+ }
232
+
233
+
219
234
  class MarkdownRenderer extends marked.Renderer {
220
235
  link(params) {
221
236
  const link = super.link(params);
@@ -455,7 +470,7 @@ export default {
455
470
  },
456
471
  };
457
472
  case 'number':
458
- const step = field.customForm ? JSON.parse(JSON.stringify(field.customForm)).step : undefined;
473
+ const step = normalizeCustomForm(field.customForm).step;
459
474
  return {
460
475
  type: 'FormKit',
461
476
  props: {
@@ -523,7 +538,7 @@ export default {
523
538
  },
524
539
  };
525
540
  case 'select':
526
- const selections = JSON.parse(JSON.stringify(field.customForm)).entries.map((obj) => {
541
+ const selections = normalizeCustomForm(field.customForm, { entries: [] }).entries.map((obj) => {
527
542
  return { value: obj.key, label: obj.value };
528
543
  });
529
544
  return {
@@ -595,7 +610,7 @@ export default {
595
610
  },
596
611
  };
597
612
  case 'file':
598
- const multiple = field.customForm ? JSON.parse(JSON.stringify(field.customForm)).multiple === 'true' : false;
613
+ const multiple = normalizeCustomForm(field.customForm, { multiple: false }).multiple === true;
599
614
  return {
600
615
  type: 'div',
601
616
  props: {
@@ -610,7 +625,7 @@ export default {
610
625
  name: name,
611
626
  };
612
627
  case 'checkbox':
613
- const options = JSON.parse(JSON.stringify(field.customForm)).entries.map((obj) => {
628
+ const options = normalizeCustomForm(field.customForm, { entries: [] }).entries.map((obj) => {
614
629
  return { value: obj.key, label: obj.value };
615
630
  });
616
631
  return {
@@ -694,10 +709,11 @@ export default {
694
709
  };
695
710
  case 'header':
696
711
  let typeToUse = 'h1';
697
- if (field.customForm && JSON.parse(JSON.stringify(field.customForm)).style === 'heading_2') {
712
+ const normalizedCustomForm = normalizeCustomForm(field.customForm);
713
+ if (normalizedCustomForm && normalizedCustomForm.style === 'heading_2') {
698
714
  typeToUse = 'h2';
699
715
  }
700
- if (field.customForm && JSON.parse(JSON.stringify(field.customForm)).style === 'heading_3') {
716
+ if (normalizedCustomForm && normalizedCustomForm.style === 'heading_3') {
701
717
  typeToUse = 'h3';
702
718
  }
703
719
  return {
@@ -762,7 +778,8 @@ export default {
762
778
  },
763
779
  };
764
780
  case 'radio':
765
- const radioOptions = JSON.parse(JSON.stringify(field.customForm)).entries.map((obj) => {
781
+ const normalizedRadioForm = normalizeCustomForm(field.customForm, { entries: [] });
782
+ const radioOptions = normalizedRadioForm.entries.map((obj) => {
766
783
  return { value: obj.key, label: obj.value };
767
784
  });
768
785
  return {
@@ -787,7 +804,7 @@ export default {
787
804
  },
788
805
  };
789
806
  case 'range':
790
- const customForm = JSON.parse(JSON.stringify(field.customForm));
807
+ const customForm = normalizeCustomForm(field.customForm);
791
808
  return {
792
809
  type: 'v-slider',
793
810
  props: {
@@ -827,7 +844,7 @@ export default {
827
844
  },
828
845
  };
829
846
  case 'textarea':
830
- const rows = field.customForm ? JSON.parse(JSON.stringify(field.customForm)).rows : undefined;
847
+ const rows = normalizeCustomForm(field.customForm, {}).rows;
831
848
  return {
832
849
  type: 'FormKit',
833
850
  props: {
@@ -1001,7 +1018,7 @@ export default {
1001
1018
  this.formData[field.id] = field.defaultValue;
1002
1019
 
1003
1020
  if (field.type === 'confirm') {
1004
- const customForm = field.customForm ? JSON.parse(JSON.stringify(field.customForm)) : {};
1021
+ const customForm = normalizeCustomForm(field.customForm, {});
1005
1022
  const confirmText = customForm.confirmButtonText ?? 'Confirm';
1006
1023
  const declineText = customForm.declineButtonText ?? 'Decline';
1007
1024
 
@@ -1228,7 +1245,7 @@ export default {
1228
1245
  }
1229
1246
 
1230
1247
  const fieldId = field.id;
1231
- const multiple = field.customForm ? JSON.parse(JSON.stringify(field.customForm)).multiple === 'true' : false;
1248
+ const multiple = normalizeCustomForm(field.customForm, { multiple: false }).multiple === true;
1232
1249
 
1233
1250
  if (fileData && typeof fileData === 'object' && fileData.name && fileData.data) {
1234
1251
  this.originalFileData[fieldId] = fileData;
@@ -1305,9 +1322,7 @@ export default {
1305
1322
  }
1306
1323
 
1307
1324
  if (fieldValue) {
1308
- const multiple = field.customForm
1309
- ? JSON.parse(JSON.stringify(field.customForm)).multiple === 'true'
1310
- : false;
1325
+ const multiple = normalizeCustomForm(field.customForm, { multiple: false }).multiple === true;
1311
1326
 
1312
1327
  if (multiple && Array.isArray(fieldValue)) {
1313
1328
  const base64Files = [];