rb-document-form-constructor 0.9.22 → 0.9.24

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.
@@ -6427,19 +6427,86 @@ var script$3 = {
6427
6427
 
6428
6428
  data() {
6429
6429
  return {
6430
- validationState: {}
6430
+ validationState: {},
6431
+ systemFieldsValues: {}
6431
6432
  };
6432
6433
  },
6433
6434
 
6434
6435
  watch: {
6435
6436
  formConfig() {
6436
6437
  this.validationState = {};
6438
+ this.systemFieldsValues = {};
6437
6439
  this.execApplyDefaultValues();
6438
6440
  this.execApplyDefaultValRule();
6439
6441
  }
6440
6442
 
6441
6443
  },
6442
6444
  methods: {
6445
+ isSystemField(field) {
6446
+ return field.isSystem === true;
6447
+ },
6448
+
6449
+ getFieldValue(field) {
6450
+ if (this.isSystemField(field)) {
6451
+ return this.systemFieldsValues[field.name];
6452
+ }
6453
+
6454
+ return this.doc[field.name];
6455
+ },
6456
+
6457
+ setFieldValue(field, value) {
6458
+ if (this.isSystemField(field)) {
6459
+ this.$set(this.systemFieldsValues, field.name, value);
6460
+ } else {
6461
+ this.$set(this.doc, field.name, value);
6462
+ }
6463
+ },
6464
+
6465
+ onFieldInput(event, field) {
6466
+ var _event$target;
6467
+
6468
+ const value = (event === null || event === void 0 ? void 0 : (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.value) !== undefined ? event.target.value : event;
6469
+ this.setFieldValue(field, value);
6470
+
6471
+ if (this.isSystemField(field)) {
6472
+ this.$emit('isSystemFieldChange', {
6473
+ event: 'input',
6474
+ fieldName: field.name,
6475
+ field: field,
6476
+ value: value
6477
+ });
6478
+ }
6479
+
6480
+ this.onEventFired('input', event, field);
6481
+ },
6482
+
6483
+ // onFieldChange(event, field) {
6484
+ // const value = event?.target?.value !== undefined ? event.target.value : event;
6485
+ // this.setFieldValue(field, value);
6486
+ // if (this.isSystemField(field)) {
6487
+ // this.$emit('isSystemFieldChange', {
6488
+ // event: 'input',
6489
+ // fieldName: field.name,
6490
+ // field: field,
6491
+ // value: value,
6492
+ // });
6493
+ // }
6494
+ // this.onEventFired('change', event, field);
6495
+ // },
6496
+ onFieldMounted(event, field) {
6497
+ if (this.isSystemField(field)) {
6498
+ const value = this.getFieldValue(field);
6499
+ this.$emit('isSystemFieldChange', {
6500
+ event: 'mounted',
6501
+ fieldName: field.name,
6502
+ field: field,
6503
+ value: value
6504
+ });
6505
+ }
6506
+
6507
+ this.onEventFired('mounted', event, field);
6508
+ },
6509
+
6443
6510
  getResolveValueName(field) {
6444
6511
  if ((field.dict || field.ref) && !field.multiple) {
6445
6512
  return field.name.substring(0, field.name.length - 2);
@@ -6526,37 +6593,49 @@ var script$3 = {
6526
6593
  UtFormConstructor.runRule(this.createRuleContext(context), rule.script);
6527
6594
  },
6528
6595
 
6529
- isValueEmpty(fieldName) {
6530
- var _this$doc$fieldName;
6596
+ getFieldValueForValidation(field) {
6597
+ return this.isSystemField(field) ? this.systemFieldsValues[field.name] : this.doc[field.name];
6598
+ },
6599
+
6600
+ isValueEmpty(field) {
6601
+ const fieldName = typeof field === 'string' ? field : field.name;
6602
+ const fieldObj = typeof field === 'string' ? null : field;
6603
+ const value = fieldObj && this.isSystemField(fieldObj) ? this.systemFieldsValues[fieldName] : this.doc[fieldName];
6531
6604
 
6532
- if (this.doc[fieldName] == null) {
6605
+ if (value == null) {
6533
6606
  return true;
6534
6607
  }
6535
6608
 
6536
- if (Array.isArray(this.doc[fieldName]) && !((_this$doc$fieldName = this.doc[fieldName]) !== null && _this$doc$fieldName !== void 0 && _this$doc$fieldName.length)) {
6609
+ if (Array.isArray(value) && !(value !== null && value !== void 0 && value.length)) {
6537
6610
  return true;
6538
6611
  }
6539
6612
 
6540
- if (_typeof(this.doc[fieldName] === 'string') && this.doc[fieldName] === '') {
6613
+ if (_typeof(value === 'string') && value === '') {
6541
6614
  return true;
6542
6615
  }
6543
6616
 
6544
6617
  return false;
6545
6618
  },
6546
6619
 
6547
- isValueLessThanMax(fieldname, max) {
6548
- if (this.doc[fieldname] && max) {
6549
- var _this$doc$fieldname;
6620
+ isValueLessThanMax(field, max) {
6621
+ const fieldName = typeof field === 'string' ? field : field.name;
6622
+ const fieldObj = typeof field === 'string' ? null : field;
6623
+ const value = fieldObj && this.isSystemField(fieldObj) ? this.systemFieldsValues[fieldName] : this.doc[fieldName];
6550
6624
 
6551
- return ((_this$doc$fieldname = this.doc[fieldname]) === null || _this$doc$fieldname === void 0 ? void 0 : _this$doc$fieldname.length) > parseInt(max);
6625
+ if (value && max) {
6626
+ return (value === null || value === void 0 ? void 0 : value.length) > parseInt(max);
6552
6627
  }
6553
6628
 
6554
6629
  return false;
6555
6630
  },
6556
6631
 
6557
- isValueLessThanMin(fieldname, min) {
6558
- if (this.doc[fieldname] && min) {
6559
- return parseInt(this.doc[fieldname]) < parseInt(min);
6632
+ isValueLessThanMin(field, min) {
6633
+ const fieldName = typeof field === 'string' ? field : field.name;
6634
+ const fieldObj = typeof field === 'string' ? null : field;
6635
+ const value = fieldObj && this.isSystemField(fieldObj) ? this.systemFieldsValues[fieldName] : this.doc[fieldName];
6636
+
6637
+ if (value && min) {
6638
+ return parseInt(value) < parseInt(min);
6560
6639
  }
6561
6640
 
6562
6641
  return false;
@@ -6571,16 +6650,16 @@ var script$3 = {
6571
6650
 
6572
6651
  let feedback = '';
6573
6652
 
6574
- if (f.required && this.isValueEmpty(f.name)) {
6653
+ if (f.required && this.isValueEmpty(f)) {
6575
6654
  feedback += this.getDisplayField(f);
6576
6655
  }
6577
6656
 
6578
- if (f.type === 'integer' && this.isValueLessThanMin(f.name, f.input.propsData.min)) {
6657
+ if (f.type === 'integer' && this.isValueLessThanMin(f, f.input.propsData.min)) {
6579
6658
  feedback += f.input.propsData.min;
6580
6659
  } // TODO: Костыль так как на бэке нету типа memo
6581
6660
 
6582
6661
 
6583
- if (f.input.type === 'b-form-textarea' && this.isValueLessThanMax(f.name, (_f$input$propsData = f.input.propsData) === null || _f$input$propsData === void 0 ? void 0 : _f$input$propsData.max)) {
6662
+ if (f.input.type === 'b-form-textarea' && this.isValueLessThanMax(f, (_f$input$propsData = f.input.propsData) === null || _f$input$propsData === void 0 ? void 0 : _f$input$propsData.max)) {
6584
6663
  var _f$input$propsData2;
6585
6664
 
6586
6665
  feedback += `\nМаксимальное значение для этого поля ${(_f$input$propsData2 = f.input.propsData) === null || _f$input$propsData2 === void 0 ? void 0 : _f$input$propsData2.max}`;
@@ -6593,13 +6672,17 @@ var script$3 = {
6593
6672
  const errors = (_UtArray$removeDuplic = UtArray.removeDuplicate(findErrors, 'field')) === null || _UtArray$removeDuplic === void 0 ? void 0 : _UtArray$removeDuplic.map(f => f === null || f === void 0 ? void 0 : f.label).join(', ');
6594
6673
  feedback = errors ? this.$t('validate.multiRequired', {
6595
6674
  field: errors
6596
- }) : this.isValueEmpty(f.name) ? this.getDisplayField(f) : '';
6675
+ }) : this.isValueEmpty(f) ? this.getDisplayField(f) : '';
6597
6676
  } // 🔥 Кастомная валидация для конкретного поля
6598
6677
 
6599
6678
 
6600
6679
  if (typeof f.validate === 'function') {
6601
- console.log(f, this.doc);
6602
- const customError = f.validate(this.doc[f.name], f, this.doc, this.formConfig);
6680
+ const fieldValue = this.getFieldValueForValidation(f);
6681
+ const docForValidation = this.isSystemField(f) ? { ...this.doc,
6682
+ [f.name]: fieldValue
6683
+ } : this.doc;
6684
+ console.log(f, docForValidation);
6685
+ const customError = f.validate(fieldValue, f, docForValidation, this.formConfig);
6603
6686
 
6604
6687
  if (customError) {
6605
6688
  feedback += `\n${customError}`;
@@ -6660,7 +6743,11 @@ var script$3 = {
6660
6743
  defValue = f.defaultValue == null ? null : f.defaultValue;
6661
6744
  }
6662
6745
 
6663
- this.$set(this.doc, f.name, f.defaultValue = defValue);
6746
+ if (this.isSystemField(f)) {
6747
+ this.$set(this.systemFieldsValues, f.name, f.defaultValue = defValue);
6748
+ } else {
6749
+ this.$set(this.doc, f.name, f.defaultValue = defValue);
6750
+ }
6664
6751
  }
6665
6752
  });
6666
6753
  });
@@ -6676,8 +6763,18 @@ var script$3 = {
6676
6763
  if (!f.defaultValue) {
6677
6764
  const rule = f.rules.find(rule => rule.event === 'defaultValue');
6678
6765
 
6679
- if (rule && !this.doc[f.name]) {
6680
- this.$set(this.doc, f.name, f.defaultValue = eval(rule.script));
6766
+ if (rule) {
6767
+ const currentValue = this.isSystemField(f) ? this.systemFieldsValues[f.name] : this.doc[f.name];
6768
+
6769
+ if (!currentValue) {
6770
+ const defValue = eval(rule.script);
6771
+
6772
+ if (this.isSystemField(f)) {
6773
+ this.$set(this.systemFieldsValues, f.name, f.defaultValue = defValue);
6774
+ } else {
6775
+ this.$set(this.doc, f.name, f.defaultValue = defValue);
6776
+ }
6777
+ }
6681
6778
  }
6682
6779
  }
6683
6780
  }
@@ -6696,7 +6793,8 @@ var script$3 = {
6696
6793
 
6697
6794
  activated() {
6698
6795
  this.execApplyDefaultValues();
6699
- this.execApplyDefaultValRule();
6796
+ this.execApplyDefaultValRule(); // this.emitSystemFieldsMounted();
6797
+
6700
6798
  this.onGlobalEventFired('form-activated', this);
6701
6799
  }
6702
6800
 
@@ -6770,6 +6868,7 @@ var __vue_render__$3 = function () {
6770
6868
  tag: "component",
6771
6869
  attrs: {
6772
6870
  "id": field.name,
6871
+ "value": _vm.getFieldValue(field),
6773
6872
  "disabled": !_vm.editable || !field.editable,
6774
6873
  "markForBackResolution": _vm.isResolvableField(field),
6775
6874
  "required": field.required,
@@ -6792,7 +6891,7 @@ var __vue_render__$3 = function () {
6792
6891
  return _vm.onEventFired('click', $event, field);
6793
6892
  },
6794
6893
  "input": function ($event) {
6795
- return _vm.onEventFired('input', $event, field);
6894
+ return _vm.onFieldInput($event, field);
6796
6895
  },
6797
6896
  "hook:created": function ($event) {
6798
6897
  return _vm.onEventFired('created', $event, field);
@@ -6804,15 +6903,8 @@ var __vue_render__$3 = function () {
6804
6903
  return _vm.onEventFired('activated', $event, field);
6805
6904
  },
6806
6905
  "hook:mounted": function ($event) {
6807
- return _vm.onEventFired('mounted', $event, field);
6906
+ return _vm.onFieldMounted($event, field);
6808
6907
  }
6809
- },
6810
- model: {
6811
- value: _vm.doc[field.name],
6812
- callback: function ($$v) {
6813
- _vm.$set(_vm.doc, field.name, $$v);
6814
- },
6815
- expression: "doc[field.name]"
6816
6908
  }
6817
6909
  }, 'component', field.input.propsData, false))], 1)], 1)], 1) : _vm._e()];
6818
6910
  })], 2)];
@@ -7932,11 +8024,11 @@ var script = {
7932
8024
 
7933
8025
  removeSection(section, index) {
7934
8026
  this.formConfig.sections.splice(index, 1);
7935
- /*UtModal.showYesNoDialog('Вы действительно хотите удалить секцию?', {
7936
- onOk: (event, modal) => {
7937
- this.formConfig.sections.splice(index, 1);
7938
- UtModal.closeModal(modal);
7939
- }
8027
+ /*UtModal.showYesNoDialog('Вы действительно хотите удалить секцию?', {
8028
+ onOk: (event, modal) => {
8029
+ this.formConfig.sections.splice(index, 1);
8030
+ UtModal.closeModal(modal);
8031
+ }
7940
8032
  });*/
7941
8033
  },
7942
8034
 
@@ -7987,7 +8079,7 @@ var script = {
7987
8079
 
7988
8080
  let found = this.multipleFieldAreOnFormConfig(field);
7989
8081
 
7990
- if (found) {
8082
+ if (found && !field.isSystem) {
7991
8083
  this.removeFieldFromColumn(field, this.columnTo, newIndex);
7992
8084
  this.resetDragVariables();
7993
8085
  this.$bvModal.msgBoxOk('На форме уже есть это поле', {