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.
@@ -1,308 +1,408 @@
1
- <template>
2
- <b-form v-if="formConfig && formConfig.sections" class="rb-doc-form" @submit.prevent>
3
- <div
4
- v-for="section in formConfig.sections"
5
- :key="section.labelRu"
6
- :class="className"
7
- class="rb-form-section"
8
- >
9
- <b-row>
10
- <b-col lg="12">
11
- <h4>{{ getDisplayField(section) }}</h4>
12
- </b-col>
13
- <template v-for="column in section.columns">
14
- <b-col :key="column.index" :lg="getColumnSize(section)" :sm="12">
15
- <template v-for="field in column.fields">
16
- {{ field.valueName }}
17
- <b-form-row v-if="field.visible" :key="field.name">
18
- <b-col lg="12">
19
- <b-form-group
20
- ref="inputContainer"
21
- :data-field="field.name"
22
- :invalid-feedback="validationState[`${field.name}__feedback`]"
23
- :state="validationState[field.name]"
24
- >
25
- <component
26
- v-bind:is="field.input.type"
27
- :id="field.name"
28
- :ref="field.ref? field.ref: field.name"
29
- v-model="doc[field.name]"
30
- :disabled="!editable || !field.editable"
31
- :markForBackResolution="isResolvableField(field)"
32
- :required="field.required"
33
- :resolve-value="getResolveValue(field)"
34
- :resolveFromObject="isResolvableField(field)"
35
- :resolveObject.sync="doc[getResolveFieldName(field)]"
36
- :state="validationState[field.name]"
37
- v-bind="field.input.propsData"
38
- @change="onEventFired('change', $event, field)"
39
- @click="onEventFired('click', $event, field)"
40
- @input="onEventFired('input', $event, field)"
41
- @hook:created="onEventFired('created', $event, field)"
42
- @hook:destroyed="onEventFired('destroyed', $event, field)"
43
- @hook:activated="onEventFired('activated', $event, field)"
44
- @hook:mounted="onEventFired('mounted', $event, field)"
45
- ></component>
46
- <template #label>
47
- <span :title="getDisplayField(field)">{{ getDisplayField(field) }}</span>
48
- <span v-if="showRequiredInLabel && field.required" class="text-danger"
49
- >*</span
50
- >
51
- </template>
52
- </b-form-group>
53
- </b-col>
54
- </b-form-row>
55
- </template>
56
- </b-col>
57
- </template>
58
- </b-row>
59
- </div>
60
- </b-form>
61
- </template>
62
-
63
- <script>
64
- import Vue from 'vue';
65
- import {UtFormConstructor} from '../utils/UtFormConstructor';
66
- import typeOf from 'typeof';
67
- import {UtFormConfig} from '@/utils/UtFormConfig';
68
- import {UtArray} from "@/utils/UtArray";
69
-
70
- export default {
71
- name: 'DocForm',
72
- props: {
73
- formConfig: Object,
74
- applyDefaultValues: {type: Boolean, default: true},
75
- doc: {type: Object, default: () => ({})},
76
- refSuffix: {type: String, default: 'Id'},
77
- editable: {type: Boolean, default: true},
78
- displayField: {type: String, default: 'labelRu'},
79
- showRequiredInLabel: {type: Boolean, default: true},
80
- className: {type: String, default: 'container'},
81
- },
82
- data() {
83
- return {
84
- validationState: {},
85
- };
86
- },
87
- watch: {
88
- formConfig() {
89
- this.validationState = {};
90
- this.execApplyDefaultValues();
91
- this.execApplyDefaultValRule();
92
- },
93
- },
94
- methods: {
95
- getResolveValueName(field) {
96
- if ((field.dict || field.ref) && !field.multiple) {
97
- return field.name.substring(0, field.name.length - 2);
98
- }
99
- return field.name;
100
- },
101
- getResolveValue(field) {
102
- return this.doc[this.getResolveValueName(field)]
103
- ? this.doc[this.getResolveValueName(field)]
104
- : null;
105
- },
106
- getDisplayField(value) {
107
- if (!value[this.displayField]) {
108
- return value.labelRu;
109
- } else {
110
- return value[this.displayField];
111
- }
112
- },
113
- isResolvableField(field) {
114
- return !!field.ref;
115
- },
116
- getResolveObject(field) {
117
- if (this.isResolvableField(field)) {
118
- let resolveFieldName = this.getResolveFieldName(field);
119
- return field.multiple ? this.doc[field.name] : this.doc[resolveFieldName];
120
- } else {
121
- return null;
122
- }
123
- },
124
- getResolveFieldName(field) {
125
- let resolveFieldName = field?.name
126
- if (resolveFieldName?.endsWith('Id')) {
127
- resolveFieldName = field.name.substring(0, field.name.length - 2);
128
- }
129
- return resolveFieldName;
130
- },
131
- onEventFired(eventName, event, field) {
132
- if (field.rules) {
133
- field.rules.forEach((rule) => {
134
- if (rule.event === eventName && rule.script) {
135
- this.runRule(rule, {event, eventName});
136
- }
137
- });
138
- }
139
- },
140
- onGlobalEventFired(eventName, event) {
141
- let fields = UtFormConfig.getFields(this.formConfig);
142
- fields.forEach((f) => {
143
- if (f.rules) {
144
- f.rules.forEach((r) => {
145
- if (r.event === eventName) {
146
- this.runRule(r, {event, eventName});
147
- }
148
- });
149
- }
150
- });
151
- },
152
- createRuleContext(additionalContext) {
153
- return Object.assign(
154
- {
155
- form: this,
156
- doc: this.doc,
157
- ...additionalContext,
158
- },
159
- UtFormConstructor.getRuleContext(),
160
- );
161
- },
162
- runRule(rule, context) {
163
- UtFormConstructor.runRule(this.createRuleContext(context), rule.script);
164
- },
165
- isValueEmpty(fieldName) {
166
- if (this.doc[fieldName] == null) {
167
- return true;
168
- }
169
- if (Array.isArray(this.doc[fieldName]) && !this.doc[fieldName]?.length) {
170
- return true;
171
- }
172
-
173
- if (typeOf(this.doc[fieldName] === 'string') && this.doc[fieldName] === '') {
174
- return true;
175
- }
176
- return false;
177
- },
178
- isValueLessThanMax(fieldname, max) {
179
- if (this.doc[fieldname] && max) {
180
- return this.doc[fieldname]?.length > parseInt(max);
181
- }
182
- return false;
183
- },
184
- isValueLessThanMin(fieldname, min) {
185
- if (this.doc[fieldname] && min) {
186
- return parseInt(this.doc[fieldname]) < parseInt(min);
187
- }
188
-
189
- return false;
190
- },
191
- validate(callback = () => {
192
- }) {
193
- this.formConfig.sections.forEach((s) => {
194
- s.columns.forEach((c) => {
195
- c.fields.forEach((f) => {
196
- let feedback = '';
197
-
198
- if (f.required && this.isValueEmpty(f.name)) {
199
- feedback += this.getDisplayField(f);
200
- }
201
-
202
- if (f.type === 'integer' && this.isValueLessThanMin(f.name, f.input.propsData.min)) {
203
- feedback += f.input.propsData.min;
204
- }
205
- // TODO: Костыль так как на бэке нету типа memo
206
- if (f.input.type === 'b-form-textarea' && this.isValueLessThanMax(f.name, f.input.propsData?.max)) {
207
- feedback += `\nМаксимальное значение для этого поля ${f.input.propsData?.max}`;
208
- }
209
-
210
- if (f.required && f.input.propsData?.isInlineTableInput) {
211
- const findErrors = this.$refs?.[f.name]?.[0]?.getIsDirty?.() ?? [];
212
- const errors = UtArray.removeDuplicate(findErrors, 'field')?.map(f => f?.label).join(', ')
213
- feedback = errors ? this.$t('validate.multiRequired', {field: errors}) : this.isValueEmpty(f.name) ? this.getDisplayField(f) : ''
214
- }
215
- // 🔥 Кастомная валидация для конкретного поля
216
- if (typeof f.validate === 'function') {
217
- console.log(f, this.doc);
218
- const customError = f.validate(this.doc[f.name], f, this.doc, this.formConfig);
219
- if (customError) {
220
- feedback += `\n${customError}`;
221
- }
222
- }
223
- if (feedback) {
224
- Vue.set(this.validationState, f.name, false);
225
- Vue.set(this.validationState, `${f.name}__feedback`, feedback);
226
- } else {
227
- Vue.set(this.validationState, f.name, null);
228
- }
229
- callback(feedback, this.$refs, f, this.doc)
230
- this.onEventFired(
231
- 'validate',
232
- {
233
- validationState: this.validationState,
234
- doc: this.doc,
235
- },
236
- f,
237
- );
238
- });
239
- });
240
- });
241
- for (let fieldName in this.validationState) {
242
- if (this.validationState[fieldName] === false) {
243
- return false;
244
- }
245
- }
246
-
247
- return true;
248
- },
249
- getColumnSize(section) {
250
- const MAX_COLUMN_SIZE = 12;
251
- if (!section || !section.columnCount) {
252
- return MAX_COLUMN_SIZE;
253
- }
254
-
255
- let colSize = Math.floor(MAX_COLUMN_SIZE / section.columnCount);
256
- return colSize;
257
- },
258
- isNotUndefinedAndNull(value) {
259
- return !(value === null || value === undefined)
260
- },
261
- execApplyDefaultValues() {
262
- if (this.applyDefaultValues) {
263
- this.formConfig.sections.forEach((r) => {
264
- r.columns.forEach((c) => {
265
- c.fields.forEach((f) => {
266
- if (this.isNotUndefinedAndNull(f.defaultValue)) {
267
- let defValue;
268
- if (this.defaultValue && typeOf(f.defaultValue) === 'function') {
269
- defValue = f.defaultValue();
270
- } else {
271
- defValue = f.defaultValue == null ? null : f.defaultValue;
272
- }
273
- this.$set(this.doc, f.name, (f.defaultValue = defValue));
274
- }
275
- });
276
- });
277
- });
278
- }
279
- },
280
- execApplyDefaultValRule() {
281
- this.formConfig.sections.forEach((el) => {
282
- el.columns.forEach((c) => {
283
- c.fields.forEach((f) => {
284
- if (f.rules) {
285
- if (!f.defaultValue) {
286
- const rule = f.rules.find((rule) => rule.event === 'defaultValue');
287
- if (rule && !this.doc[f.name]) {
288
- this.$set(this.doc, f.name, (f.defaultValue = eval(rule.script)));
289
- }
290
- }
291
- }
292
- });
293
- });
294
- });
295
- },
296
- },
297
- mounted() {
298
- this.execApplyDefaultValues();
299
- this.execApplyDefaultValRule();
300
- this.onGlobalEventFired('form-mounted', this);
301
- },
302
- activated() {
303
- this.execApplyDefaultValues();
304
- this.execApplyDefaultValRule();
305
- this.onGlobalEventFired('form-activated', this);
306
- },
307
- };
308
- </script>
1
+ <template>
2
+ <b-form v-if="formConfig && formConfig.sections" class="rb-doc-form" @submit.prevent>
3
+ <div
4
+ v-for="section in formConfig.sections"
5
+ :key="section.labelRu"
6
+ :class="className"
7
+ class="rb-form-section"
8
+ >
9
+ <b-row>
10
+ <b-col lg="12">
11
+ <h4>{{ getDisplayField(section) }}</h4>
12
+ </b-col>
13
+ <template v-for="column in section.columns">
14
+ <b-col :key="column.index" :lg="getColumnSize(section)" :sm="12">
15
+ <template v-for="field in column.fields">
16
+ {{ field.valueName }}
17
+ <b-form-row v-if="field.visible" :key="field.name">
18
+ <b-col lg="12">
19
+ <b-form-group
20
+ ref="inputContainer"
21
+ :data-field="field.name"
22
+ :invalid-feedback="validationState[`${field.name}__feedback`]"
23
+ :state="validationState[field.name]"
24
+ >
25
+ <component
26
+ v-bind:is="field.input.type"
27
+ :id="field.name"
28
+ :ref="field.ref? field.ref: field.name"
29
+ :value="getFieldValue(field)"
30
+ :disabled="!editable || !field.editable"
31
+ :markForBackResolution="isResolvableField(field)"
32
+ :required="field.required"
33
+ :resolve-value="getResolveValue(field)"
34
+ :resolveFromObject="isResolvableField(field)"
35
+ :resolveObject.sync="doc[getResolveFieldName(field)]"
36
+ :state="validationState[field.name]"
37
+ v-bind="field.input.propsData"
38
+ @change="onEventFired('change', $event, field)"
39
+ @click="onEventFired('click', $event, field)"
40
+ @input="onFieldInput($event, field)"
41
+ @hook:created="onEventFired('created', $event, field)"
42
+ @hook:destroyed="onEventFired('destroyed', $event, field)"
43
+ @hook:activated="onEventFired('activated', $event, field)"
44
+ @hook:mounted="onFieldMounted($event, field)"
45
+ ></component>
46
+ <template #label>
47
+ <span :title="getDisplayField(field)">{{ getDisplayField(field) }}</span>
48
+ <span v-if="showRequiredInLabel && field.required" class="text-danger"
49
+ >*</span
50
+ >
51
+ </template>
52
+ </b-form-group>
53
+ </b-col>
54
+ </b-form-row>
55
+ </template>
56
+ </b-col>
57
+ </template>
58
+ </b-row>
59
+ </div>
60
+ </b-form>
61
+ </template>
62
+
63
+ <script>
64
+ import Vue from 'vue';
65
+ import {UtFormConstructor} from '../utils/UtFormConstructor';
66
+ import typeOf from 'typeof';
67
+ import {UtFormConfig} from '@/utils/UtFormConfig';
68
+ import {UtArray} from "@/utils/UtArray";
69
+
70
+ export default {
71
+ name: 'DocForm',
72
+ props: {
73
+ formConfig: Object,
74
+ applyDefaultValues: {type: Boolean, default: true},
75
+ doc: {type: Object, default: () => ({})},
76
+ refSuffix: {type: String, default: 'Id'},
77
+ editable: {type: Boolean, default: true},
78
+ displayField: {type: String, default: 'labelRu'},
79
+ showRequiredInLabel: {type: Boolean, default: true},
80
+ className: {type: String, default: 'container'},
81
+ },
82
+ data() {
83
+ return {
84
+ validationState: {},
85
+ systemFieldsValues: {},
86
+ };
87
+ },
88
+ watch: {
89
+ formConfig() {
90
+ this.validationState = {};
91
+ this.systemFieldsValues = {};
92
+ this.execApplyDefaultValues();
93
+ this.execApplyDefaultValRule();
94
+ },
95
+ },
96
+ methods: {
97
+ isSystemField(field) {
98
+ return field.isSystem === true;
99
+ },
100
+ getFieldValue(field) {
101
+ if (this.isSystemField(field)) {
102
+ return this.systemFieldsValues[field.name];
103
+ }
104
+ return this.doc[field.name];
105
+ },
106
+ setFieldValue(field, value) {
107
+ if (this.isSystemField(field)) {
108
+ this.$set(this.systemFieldsValues, field.name, value);
109
+ } else {
110
+ this.$set(this.doc, field.name, value);
111
+ }
112
+ },
113
+ onFieldInput(event, field) {
114
+ const value = event?.target?.value !== undefined ? event.target.value : event;
115
+ this.setFieldValue(field, value);
116
+
117
+ if (this.isSystemField(field)) {
118
+ this.$emit('isSystemFieldChange', {
119
+ event: 'input',
120
+ fieldName: field.name,
121
+ field: field,
122
+ value: value,
123
+ });
124
+ }
125
+ this.onEventFired('input', event, field);
126
+ },
127
+ // onFieldChange(event, field) {
128
+ // const value = event?.target?.value !== undefined ? event.target.value : event;
129
+ // this.setFieldValue(field, value);
130
+
131
+ // if (this.isSystemField(field)) {
132
+ // this.$emit('isSystemFieldChange', {
133
+ // event: 'input',
134
+ // fieldName: field.name,
135
+ // field: field,
136
+ // value: value,
137
+ // });
138
+ // }
139
+ // this.onEventFired('change', event, field);
140
+ // },
141
+ onFieldMounted(event, field) {
142
+ if (this.isSystemField(field)) {
143
+ const value = this.getFieldValue(field);
144
+ this.$emit('isSystemFieldChange', {
145
+ event: 'mounted',
146
+ fieldName: field.name,
147
+ field: field,
148
+ value: value,
149
+ });
150
+ }
151
+ this.onEventFired('mounted', event, field);
152
+ },
153
+ getResolveValueName(field) {
154
+ if ((field.dict || field.ref) && !field.multiple) {
155
+ return field.name.substring(0, field.name.length - 2);
156
+ }
157
+ return field.name;
158
+ },
159
+ getResolveValue(field) {
160
+ return this.doc[this.getResolveValueName(field)]
161
+ ? this.doc[this.getResolveValueName(field)]
162
+ : null;
163
+ },
164
+ getDisplayField(value) {
165
+ if (!value[this.displayField]) {
166
+ return value.labelRu;
167
+ } else {
168
+ return value[this.displayField];
169
+ }
170
+ },
171
+ isResolvableField(field) {
172
+ return !!field.ref;
173
+ },
174
+ getResolveObject(field) {
175
+ if (this.isResolvableField(field)) {
176
+ let resolveFieldName = this.getResolveFieldName(field);
177
+ return field.multiple ? this.doc[field.name] : this.doc[resolveFieldName];
178
+ } else {
179
+ return null;
180
+ }
181
+ },
182
+ getResolveFieldName(field) {
183
+ let resolveFieldName = field?.name
184
+ if (resolveFieldName?.endsWith('Id')) {
185
+ resolveFieldName = field.name.substring(0, field.name.length - 2);
186
+ }
187
+ return resolveFieldName;
188
+ },
189
+ onEventFired(eventName, event, field) {
190
+ if (field.rules) {
191
+ field.rules.forEach((rule) => {
192
+ if (rule.event === eventName && rule.script) {
193
+ this.runRule(rule, {event, eventName});
194
+ }
195
+ });
196
+ }
197
+ },
198
+ onGlobalEventFired(eventName, event) {
199
+ let fields = UtFormConfig.getFields(this.formConfig);
200
+ fields.forEach((f) => {
201
+ if (f.rules) {
202
+ f.rules.forEach((r) => {
203
+ if (r.event === eventName) {
204
+ this.runRule(r, {event, eventName});
205
+ }
206
+ });
207
+ }
208
+ });
209
+ },
210
+ createRuleContext(additionalContext) {
211
+ return Object.assign(
212
+ {
213
+ form: this,
214
+ doc: this.doc,
215
+ ...additionalContext,
216
+ },
217
+ UtFormConstructor.getRuleContext(),
218
+ );
219
+ },
220
+ runRule(rule, context) {
221
+ UtFormConstructor.runRule(this.createRuleContext(context), rule.script);
222
+ },
223
+ getFieldValueForValidation(field) {
224
+ return this.isSystemField(field)
225
+ ? this.systemFieldsValues[field.name]
226
+ : this.doc[field.name];
227
+ },
228
+ isValueEmpty(field) {
229
+ const fieldName = typeof field === 'string' ? field : field.name;
230
+ const fieldObj = typeof field === 'string' ? null : field;
231
+ const value = fieldObj && this.isSystemField(fieldObj)
232
+ ? this.systemFieldsValues[fieldName]
233
+ : this.doc[fieldName];
234
+
235
+ if (value == null) {
236
+ return true;
237
+ }
238
+ if (Array.isArray(value) && !value?.length) {
239
+ return true;
240
+ }
241
+
242
+ if (typeOf(value === 'string') && value === '') {
243
+ return true;
244
+ }
245
+ return false;
246
+ },
247
+ isValueLessThanMax(field, max) {
248
+ const fieldName = typeof field === 'string' ? field : field.name;
249
+ const fieldObj = typeof field === 'string' ? null : field;
250
+ const value = fieldObj && this.isSystemField(fieldObj)
251
+ ? this.systemFieldsValues[fieldName]
252
+ : this.doc[fieldName];
253
+
254
+ if (value && max) {
255
+ return value?.length > parseInt(max);
256
+ }
257
+ return false;
258
+ },
259
+ isValueLessThanMin(field, min) {
260
+ const fieldName = typeof field === 'string' ? field : field.name;
261
+ const fieldObj = typeof field === 'string' ? null : field;
262
+ const value = fieldObj && this.isSystemField(fieldObj)
263
+ ? this.systemFieldsValues[fieldName]
264
+ : this.doc[fieldName];
265
+
266
+ if (value && min) {
267
+ return parseInt(value) < parseInt(min);
268
+ }
269
+
270
+ return false;
271
+ },
272
+ validate(callback = () => {
273
+ }) {
274
+ this.formConfig.sections.forEach((s) => {
275
+ s.columns.forEach((c) => {
276
+ c.fields.forEach((f) => {
277
+ let feedback = '';
278
+
279
+ if (f.required && this.isValueEmpty(f)) {
280
+ feedback += this.getDisplayField(f);
281
+ }
282
+
283
+ if (f.type === 'integer' && this.isValueLessThanMin(f, f.input.propsData.min)) {
284
+ feedback += f.input.propsData.min;
285
+ }
286
+ // TODO: Костыль так как на бэке нету типа memo
287
+ if (f.input.type === 'b-form-textarea' && this.isValueLessThanMax(f, f.input.propsData?.max)) {
288
+ feedback += `\nМаксимальное значение для этого поля ${f.input.propsData?.max}`;
289
+ }
290
+
291
+ if (f.required && f.input.propsData?.isInlineTableInput) {
292
+ const findErrors = this.$refs?.[f.name]?.[0]?.getIsDirty?.() ?? [];
293
+ const errors = UtArray.removeDuplicate(findErrors, 'field')?.map(f => f?.label).join(', ')
294
+ feedback = errors ? this.$t('validate.multiRequired', {field: errors}) : this.isValueEmpty(f) ? this.getDisplayField(f) : ''
295
+ }
296
+ // 🔥 Кастомная валидация для конкретного поля
297
+ if (typeof f.validate === 'function') {
298
+ const fieldValue = this.getFieldValueForValidation(f);
299
+ const docForValidation = this.isSystemField(f)
300
+ ? { ...this.doc, [f.name]: fieldValue }
301
+ : this.doc;
302
+ console.log(f, docForValidation);
303
+ const customError = f.validate(fieldValue, f, docForValidation, this.formConfig);
304
+ if (customError) {
305
+ feedback += `\n${customError}`;
306
+ }
307
+ }
308
+ if (feedback) {
309
+ Vue.set(this.validationState, f.name, false);
310
+ Vue.set(this.validationState, `${f.name}__feedback`, feedback);
311
+ } else {
312
+ Vue.set(this.validationState, f.name, null);
313
+ }
314
+ callback(feedback, this.$refs, f, this.doc)
315
+ this.onEventFired(
316
+ 'validate',
317
+ {
318
+ validationState: this.validationState,
319
+ doc: this.doc,
320
+ },
321
+ f,
322
+ );
323
+ });
324
+ });
325
+ });
326
+ for (let fieldName in this.validationState) {
327
+ if (this.validationState[fieldName] === false) {
328
+ return false;
329
+ }
330
+ }
331
+
332
+ return true;
333
+ },
334
+ getColumnSize(section) {
335
+ const MAX_COLUMN_SIZE = 12;
336
+ if (!section || !section.columnCount) {
337
+ return MAX_COLUMN_SIZE;
338
+ }
339
+
340
+ let colSize = Math.floor(MAX_COLUMN_SIZE / section.columnCount);
341
+ return colSize;
342
+ },
343
+ isNotUndefinedAndNull(value) {
344
+ return !(value === null || value === undefined)
345
+ },
346
+ execApplyDefaultValues() {
347
+ if (this.applyDefaultValues) {
348
+ this.formConfig.sections.forEach((r) => {
349
+ r.columns.forEach((c) => {
350
+ c.fields.forEach((f) => {
351
+ if (this.isNotUndefinedAndNull(f.defaultValue)) {
352
+ let defValue;
353
+ if (this.defaultValue && typeOf(f.defaultValue) === 'function') {
354
+ defValue = f.defaultValue();
355
+ } else {
356
+ defValue = f.defaultValue == null ? null : f.defaultValue;
357
+ }
358
+ if (this.isSystemField(f)) {
359
+ this.$set(this.systemFieldsValues, f.name, (f.defaultValue = defValue));
360
+ } else {
361
+ this.$set(this.doc, f.name, (f.defaultValue = defValue));
362
+ }
363
+ }
364
+ });
365
+ });
366
+ });
367
+ }
368
+ },
369
+ execApplyDefaultValRule() {
370
+ this.formConfig.sections.forEach((el) => {
371
+ el.columns.forEach((c) => {
372
+ c.fields.forEach((f) => {
373
+ if (f.rules) {
374
+ if (!f.defaultValue) {
375
+ const rule = f.rules.find((rule) => rule.event === 'defaultValue');
376
+ if (rule) {
377
+ const currentValue = this.isSystemField(f)
378
+ ? this.systemFieldsValues[f.name]
379
+ : this.doc[f.name];
380
+ if (!currentValue) {
381
+ const defValue = eval(rule.script);
382
+ if (this.isSystemField(f)) {
383
+ this.$set(this.systemFieldsValues, f.name, (f.defaultValue = defValue));
384
+ } else {
385
+ this.$set(this.doc, f.name, (f.defaultValue = defValue));
386
+ }
387
+ }
388
+ }
389
+ }
390
+ }
391
+ });
392
+ });
393
+ });
394
+ },
395
+ },
396
+ mounted() {
397
+ this.execApplyDefaultValues();
398
+ this.execApplyDefaultValRule();
399
+ this.onGlobalEventFired('form-mounted', this);
400
+ },
401
+ activated() {
402
+ this.execApplyDefaultValues();
403
+ this.execApplyDefaultValRule();
404
+ // this.emitSystemFieldsMounted();
405
+ this.onGlobalEventFired('form-activated', this);
406
+ },
407
+ };
408
+ </script>