tuain-ng-forms-lib 17.2.22 → 17.2.23
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/esm2022/lib/classes/forms/action.mjs +106 -0
- package/esm2022/lib/classes/forms/element.mjs +25 -0
- package/esm2022/lib/classes/forms/field.mjs +474 -0
- package/esm2022/lib/classes/forms/form.constants.mjs +26 -0
- package/esm2022/lib/classes/forms/form.mjs +608 -0
- package/esm2022/lib/classes/forms/piece-propagate.mjs +39 -0
- package/esm2022/lib/classes/forms/piece.mjs +134 -0
- package/esm2022/lib/classes/forms/section.mjs +151 -0
- package/esm2022/lib/classes/forms/subsection.mjs +99 -0
- package/esm2022/lib/classes/forms/table/action.mjs +38 -0
- package/esm2022/lib/classes/forms/table/column.mjs +74 -0
- package/esm2022/lib/classes/forms/table/row-data.mjs +116 -0
- package/esm2022/lib/classes/forms/table/table.mjs +535 -0
- package/esm2022/lib/components/elements/action.component.mjs +70 -0
- package/esm2022/lib/components/elements/field.component.mjs +115 -0
- package/esm2022/lib/components/elements/layout/element.component.mjs +21 -0
- package/esm2022/lib/components/elements/layout/form-error.component.mjs +23 -0
- package/esm2022/lib/components/elements/layout/form-header.component.mjs +23 -0
- package/esm2022/lib/components/elements/layout/piece.component.mjs +64 -0
- package/esm2022/lib/components/elements/layout/section.component.mjs +56 -0
- package/esm2022/lib/components/elements/layout/sub-section.component.mjs +56 -0
- package/esm2022/lib/components/elements/tables/table-record-action.component.mjs +72 -0
- package/esm2022/lib/components/elements/tables/table-record-field.component.mjs +31 -0
- package/esm2022/lib/components/elements/tables/table.component.mjs +109 -0
- package/esm2022/lib/components/forms/basic-form.mjs +1408 -0
- package/esm2022/lib/services/event-manager.service.mjs +43 -0
- package/esm2022/lib/services/file-manager.service.mjs +7 -0
- package/esm2022/lib/services/form-manager.service.mjs +81 -0
- package/esm2022/lib/tuain-ng-forms-lib.module.mjs +71 -0
- package/esm2022/public-api.mjs +19 -0
- package/esm2022/tuain-ng-forms-lib.mjs +5 -0
- package/fesm2022/tuain-ng-forms-lib.mjs +4602 -0
- package/fesm2022/tuain-ng-forms-lib.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/classes/forms/action.d.ts +40 -0
- package/lib/classes/forms/element.d.ts +9 -0
- package/lib/classes/forms/field.d.ts +206 -0
- package/lib/classes/forms/form.constants.d.ts +25 -0
- package/lib/classes/forms/form.d.ts +232 -0
- package/lib/classes/forms/piece-propagate.d.ts +13 -0
- package/lib/classes/forms/piece.d.ts +51 -0
- package/lib/classes/forms/section.d.ts +43 -0
- package/lib/classes/forms/subsection.d.ts +42 -0
- package/lib/classes/forms/table/action.d.ts +16 -0
- package/lib/classes/forms/table/column.d.ts +33 -0
- package/lib/classes/forms/table/row-data.d.ts +14 -0
- package/lib/classes/forms/table/table.d.ts +145 -0
- package/lib/components/elements/action.component.d.ts +22 -0
- package/lib/components/elements/field.component.d.ts +47 -0
- package/lib/components/elements/layout/element.component.d.ts +8 -0
- package/lib/components/elements/layout/form-error.component.d.ts +8 -0
- package/lib/components/elements/layout/form-header.component.d.ts +9 -0
- package/lib/components/elements/layout/piece.component.d.ts +18 -0
- package/lib/components/elements/layout/section.component.d.ts +13 -0
- package/lib/components/elements/layout/sub-section.component.d.ts +13 -0
- package/lib/components/elements/tables/table-record-action.component.d.ts +18 -0
- package/lib/components/elements/tables/table-record-field.component.d.ts +12 -0
- package/lib/components/elements/tables/table.component.d.ts +44 -0
- package/lib/components/forms/basic-form.d.ts +257 -0
- package/lib/services/event-manager.service.d.ts +11 -0
- package/lib/services/file-manager.service.d.ts +6 -0
- package/lib/services/form-manager.service.d.ts +28 -0
- package/lib/tuain-ng-forms-lib.module.d.ts +20 -0
- package/package.json +16 -2
- package/{src/public-api.ts → public-api.d.ts} +0 -5
- package/.browserslistrc +0 -16
- package/.yarn/cache/nanoid-npm-4.0.0-924f5c6312-7d5946df5c.zip +0 -0
- package/.yarn/cache/tslib-npm-2.4.1-36f0ed04db-19480d6e03.zip +0 -0
- package/.yarn/cache/yn-npm-5.0.0-b001dab23c-f0ec7710d3.zip +0 -0
- package/.yarn/install-state.gz +0 -0
- package/karma.conf.js +0 -44
- package/ng-package.json +0 -11
- package/src/lib/classes/forms/action.ts +0 -117
- package/src/lib/classes/forms/element.ts +0 -26
- package/src/lib/classes/forms/field.ts +0 -522
- package/src/lib/classes/forms/form.constants.ts +0 -28
- package/src/lib/classes/forms/form.ts +0 -692
- package/src/lib/classes/forms/piece-propagate.ts +0 -47
- package/src/lib/classes/forms/piece.ts +0 -164
- package/src/lib/classes/forms/section.ts +0 -165
- package/src/lib/classes/forms/subsection.ts +0 -109
- package/src/lib/classes/forms/table/action.ts +0 -41
- package/src/lib/classes/forms/table/column.ts +0 -94
- package/src/lib/classes/forms/table/row-data.ts +0 -121
- package/src/lib/classes/forms/table/table.ts +0 -582
- package/src/lib/components/elements/action.component.ts +0 -70
- package/src/lib/components/elements/field.component.ts +0 -115
- package/src/lib/components/elements/layout/element.component.ts +0 -14
- package/src/lib/components/elements/layout/form-error.component.ts +0 -11
- package/src/lib/components/elements/layout/form-header.component.ts +0 -14
- package/src/lib/components/elements/layout/piece.component.ts +0 -60
- package/src/lib/components/elements/layout/section.component.ts +0 -52
- package/src/lib/components/elements/layout/sub-section.component.ts +0 -52
- package/src/lib/components/elements/tables/table-record-action.component.ts +0 -66
- package/src/lib/components/elements/tables/table-record-field.component.ts +0 -20
- package/src/lib/components/elements/tables/table.component.ts +0 -112
- package/src/lib/components/forms/basic-form.ts +0 -1464
- package/src/lib/services/event-manager.service.ts +0 -45
- package/src/lib/services/file-manager.service.ts +0 -7
- package/src/lib/services/form-manager.service.ts +0 -89
- package/src/lib/services/icon-dictionary.service.ts +0 -159
- package/src/lib/tuain-ng-forms-lib.module.ts +0 -40
- package/src/test.ts +0 -27
- package/tsconfig.lib.json +0 -15
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -17
|
@@ -1,522 +0,0 @@
|
|
|
1
|
-
import { Subject } from 'rxjs';
|
|
2
|
-
import yn from 'yn';
|
|
3
|
-
import { elementTypes, NO_ERROR } from './form.constants';
|
|
4
|
-
import { FormElement } from './element';
|
|
5
|
-
|
|
6
|
-
const UNDEFINED = 'undefined';
|
|
7
|
-
|
|
8
|
-
const DEFAULT_ERROR_TYPE = 'error';
|
|
9
|
-
const DEFAULT_CAPTURE_TYPE = 'INPUT';
|
|
10
|
-
const DEFAULT_ALIGNMENT = 'left';
|
|
11
|
-
|
|
12
|
-
const STD_MAX_LENGTH = 50;
|
|
13
|
-
const BIG_MAX_LENGTH = 500;
|
|
14
|
-
|
|
15
|
-
const directChanges = [
|
|
16
|
-
'defaultEditable', 'defaultValue', 'alignment', 'required', 'errorCode', 'errorMessage', 'errorType',
|
|
17
|
-
'tooltip', 'info', 'format', 'intrinsicErrorMessage', 'outputOnly', 'captureType', 'title', 'type',
|
|
18
|
-
'maxLength', 'maxValue', 'minLength', 'minValue', 'validateOnServer', 'serverAction', 'visibleLabel',
|
|
19
|
-
'options', 'placeholder',
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
const attrs = {
|
|
23
|
-
captureType: { name: '_captureType', propagate: 'captureType' },
|
|
24
|
-
errorCode: { name: '_errorCode', propagate: 'errorCode' },
|
|
25
|
-
errorMessage: { name: '_errorMessage', propagate: 'errorMessage' },
|
|
26
|
-
errorType: { name: '_errorType', propagate: 'errorType' },
|
|
27
|
-
defaultValue: { name: '_defaultValue', propagate: 'defaultValue' },
|
|
28
|
-
defaultEditable: { name: '_defaultEditable', propagate: 'defaultEditable' },
|
|
29
|
-
fieldAlignment: { name: '_fieldAlignment', propagate: 'alignment' },
|
|
30
|
-
fieldCode: { name: '_fieldCode', propagate: 'code' },
|
|
31
|
-
fieldInfo: { name: '_fieldInfo', propagate: 'info' },
|
|
32
|
-
fieldRequired: { name: '_fieldRequired', propagate: 'required' },
|
|
33
|
-
fieldTitle: { name: '_fieldTitle', propagate: 'title' },
|
|
34
|
-
fieldType: { name: '_fieldType', propagate: 'type' },
|
|
35
|
-
fieldFormat: { name: '_fieldFormat', propagate: 'format' },
|
|
36
|
-
fieldOptions: { name: '_fieldOptions', propagate: 'options' },
|
|
37
|
-
focus: { name: '_focus', propagate: 'focus' },
|
|
38
|
-
hasChanged: { name: '_hasChanged', propagate: 'hasChanged' },
|
|
39
|
-
intrinsicErrorMessage: { name: '_intrinsicErrorMessage', propagate: null },
|
|
40
|
-
maxLength: { name: '_maxLength', propagate: 'maxLength' },
|
|
41
|
-
maxValue: { name: '_maxValue', propagate: 'maxValue' },
|
|
42
|
-
minLength: { name: '_minLength', propagate: 'minLength' },
|
|
43
|
-
minValue: { name: '_minValue', propagate: 'minValue' },
|
|
44
|
-
onValidation: { name: '_onValidation', propagate: 'onValidation' },
|
|
45
|
-
outputOnly: { name: '_outputOnly', propagate: 'outputOnly' },
|
|
46
|
-
placeholder: { name: '_placeholder', propagate: 'placeholder' },
|
|
47
|
-
tooltipText: { name: '_tooltipText', propagate: 'tooltip' },
|
|
48
|
-
validateOnServer: { name: '_validateOnServer', propagate: 'validateOnServer' },
|
|
49
|
-
value: { name: '_value', propagate: 'value' },
|
|
50
|
-
visibleLabel: { name: '_visibleLabel', propagate: 'visibleLabel' },
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export interface DetailEvent {
|
|
54
|
-
code: string;
|
|
55
|
-
detail: any;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface FieldOption {
|
|
59
|
-
fieldOptionValue: string;
|
|
60
|
-
fieldOptionId: string;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export class FieldDescriptor extends FormElement {
|
|
64
|
-
private readonly _customEvent = new Subject<any>();
|
|
65
|
-
private readonly _editionFinish = new Subject<any>();
|
|
66
|
-
private readonly _editionPartial = new Subject<any>();
|
|
67
|
-
private readonly _detailRequest = new Subject<DetailEvent>();
|
|
68
|
-
|
|
69
|
-
private _errorType: string = '';
|
|
70
|
-
private _errorCode: string = '';
|
|
71
|
-
private _errorMessage: string = '';
|
|
72
|
-
private _intrinsicErrorMessage: string = '';
|
|
73
|
-
private _minValue: any;
|
|
74
|
-
private _maxValue: any;
|
|
75
|
-
private _maxLength: number = 0;
|
|
76
|
-
private _minLength: number = 0;
|
|
77
|
-
private _focus: boolean = false;
|
|
78
|
-
private _onValidation: boolean = false;
|
|
79
|
-
private _validateOnServer: boolean = false;
|
|
80
|
-
private _value: any;
|
|
81
|
-
private _visibleLabel: boolean = false;
|
|
82
|
-
private _captureType: string = '';
|
|
83
|
-
private _defaultValue: any = '';
|
|
84
|
-
private _defaultEditable: boolean = false;
|
|
85
|
-
private _externalValue: any;
|
|
86
|
-
private _fieldAlignment: string = '';
|
|
87
|
-
private _fieldInfo: any = '';
|
|
88
|
-
private _fieldRequired: boolean = false;
|
|
89
|
-
private _fieldTitle: string = '';
|
|
90
|
-
private _fieldType: string = '';
|
|
91
|
-
private _fieldFormat: RegExp | null = null;
|
|
92
|
-
private _hasChanged: boolean = false;
|
|
93
|
-
private _outputOnly: boolean = false;
|
|
94
|
-
private _tooltipText: string = '';
|
|
95
|
-
private _placeholder: string = '';
|
|
96
|
-
private _fieldCode: string = '';
|
|
97
|
-
private _fieldOptions: FieldOption[] | null = null;
|
|
98
|
-
|
|
99
|
-
constructor(inputFieldReceived, formConfig) {
|
|
100
|
-
super(inputFieldReceived, formConfig);
|
|
101
|
-
this.propagationCustomAttributes = this._formConfig?.propagationCustomAttributes?.fields ?? [];
|
|
102
|
-
this.elementType = elementTypes.field;
|
|
103
|
-
const fld = (inputFieldReceived) ? inputFieldReceived : {};
|
|
104
|
-
this.setAttr(attrs.fieldCode, fld.fieldCode);
|
|
105
|
-
this.title = fld.fieldTitle ?? this._fieldCode;
|
|
106
|
-
this.placeholder = fld.placeholder ?? this.title;
|
|
107
|
-
this.type = fld.fieldTypeCode;
|
|
108
|
-
this.captureType = fld.captureType ?? DEFAULT_CAPTURE_TYPE;
|
|
109
|
-
|
|
110
|
-
const defaultValue = fld.defaultValue ?? null;
|
|
111
|
-
if (this._fieldType === this._formConfig.fieldTypes.boolean) {
|
|
112
|
-
this.defaultValue = defaultValue ?? false;
|
|
113
|
-
} else {
|
|
114
|
-
this.defaultValue = defaultValue;
|
|
115
|
-
}
|
|
116
|
-
const defaultTypeAlignment = (this._formConfig.tableFieldStyles[this._fieldType] != null)
|
|
117
|
-
? this._formConfig.tableFieldStyles[this._fieldType]['text-align'] : DEFAULT_ALIGNMENT;
|
|
118
|
-
const fieldAlignment = (fld.alignment != null) ? fld.alignment.toLowerCase() : defaultTypeAlignment;
|
|
119
|
-
this.alignment = fieldAlignment;
|
|
120
|
-
this.info = fld.info || '';
|
|
121
|
-
let fieldFormat;
|
|
122
|
-
try {
|
|
123
|
-
if (fld.format && typeof fld.format === 'string') {
|
|
124
|
-
fieldFormat = new RegExp(fld.format);
|
|
125
|
-
} else if (fld.format?.regExp) {
|
|
126
|
-
fieldFormat = new RegExp(fld.format?.regExp);
|
|
127
|
-
}
|
|
128
|
-
} catch (e) {
|
|
129
|
-
fieldFormat = null;
|
|
130
|
-
}
|
|
131
|
-
this.format = fieldFormat;
|
|
132
|
-
this.validateOnServer = fld.serverAction ?? false;
|
|
133
|
-
this.tooltip = fld.tooltip || '';
|
|
134
|
-
this.defaultEditable = this.enabled;
|
|
135
|
-
this.required = fld.required ?? false;
|
|
136
|
-
this.outputOnly = fld.outputOnly ?? false;
|
|
137
|
-
this.minLength = fld.minLength ?? 0;
|
|
138
|
-
this.maxLength = fld.maxLength || (this._captureType === 'TEXTAREA' ? BIG_MAX_LENGTH : STD_MAX_LENGTH);
|
|
139
|
-
this.intrinsicErrorMessage = this._formConfig?.fieldValidations?.[this._fieldType]?.message
|
|
140
|
-
?? this._formConfig?.fieldValidations?.DEFAULT?.message ?? '';
|
|
141
|
-
|
|
142
|
-
this.setError(fld.errorCode, fld.errorMessage, fld.errorType ?? DEFAULT_ERROR_TYPE);
|
|
143
|
-
this.setEditable(fld.editable ?? true);
|
|
144
|
-
this.visibleLabel = fld.visibleLabel ?? true;
|
|
145
|
-
this.setVisibility(fld.visible);
|
|
146
|
-
this.options = fld.fieldOptions;
|
|
147
|
-
this._setValue(fld.fieldValue ?? this._defaultValue ?? '');
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
get alignment() { return this._fieldAlignment; }
|
|
151
|
-
set alignment(alignment) { this.setAttr(attrs.fieldAlignment, alignment); }
|
|
152
|
-
get backend() { return this._validateOnServer; }
|
|
153
|
-
|
|
154
|
-
get captureType() { return this._captureType; }
|
|
155
|
-
set captureType(captureType) { this.setAttr(attrs.captureType, captureType); }
|
|
156
|
-
|
|
157
|
-
get placeholder() { return this._placeholder; }
|
|
158
|
-
set placeholder(placeholder) { this.setAttr(attrs.placeholder, placeholder); }
|
|
159
|
-
|
|
160
|
-
get code() { return this._fieldCode; }
|
|
161
|
-
get defaultValue() { return this._defaultValue; }
|
|
162
|
-
set defaultValue(defaultValue) { this.setAttr(attrs.defaultValue, defaultValue); }
|
|
163
|
-
get defaultEditable() { return this._defaultEditable; }
|
|
164
|
-
set defaultEditable(editable) { this.setAttr(attrs.defaultEditable, editable); }
|
|
165
|
-
get detailRequest() { return this._detailRequest.asObservable(); }
|
|
166
|
-
get customEvent() { return this._customEvent.asObservable(); }
|
|
167
|
-
get editionFinish() { return this._editionFinish.asObservable(); }
|
|
168
|
-
get editionPartial() { return this._editionPartial.asObservable(); }
|
|
169
|
-
|
|
170
|
-
get empty(): boolean {
|
|
171
|
-
const fieldCurrentValue = this.value;
|
|
172
|
-
if (fieldCurrentValue === undefined || fieldCurrentValue === null) {
|
|
173
|
-
return true;
|
|
174
|
-
}
|
|
175
|
-
if (this._fieldType === this._formConfig.fieldTypes.array
|
|
176
|
-
&& Array.isArray(fieldCurrentValue) && fieldCurrentValue.length === 0) {
|
|
177
|
-
return true;
|
|
178
|
-
};
|
|
179
|
-
if (this._fieldType === this._formConfig.fieldTypes.phone) {
|
|
180
|
-
if (!Array.isArray(fieldCurrentValue)) {
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
if (fieldCurrentValue.length !== 2 || !fieldCurrentValue[0] || !fieldCurrentValue[1]) {
|
|
184
|
-
return true;
|
|
185
|
-
}
|
|
186
|
-
return false;
|
|
187
|
-
};
|
|
188
|
-
const arrayFieldTypes = this._formConfig.arrayFieldTypes ?? null;
|
|
189
|
-
if (arrayFieldTypes && Object.keys(arrayFieldTypes).includes(this._fieldType)) {
|
|
190
|
-
let arraySize = arrayFieldTypes[this._fieldType];
|
|
191
|
-
arraySize = !Number.isNaN(+arraySize) ? +arraySize : 0;
|
|
192
|
-
if (arraySize === 0) {
|
|
193
|
-
return (Array.isArray(fieldCurrentValue) && fieldCurrentValue.length === 0);
|
|
194
|
-
}
|
|
195
|
-
return (Array.isArray(fieldCurrentValue) && fieldCurrentValue.length < arraySize);
|
|
196
|
-
};
|
|
197
|
-
return fieldCurrentValue === '';
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
get error() { return { type: this._errorType, code: this._errorCode, message: this._errorMessage }; }
|
|
201
|
-
set error(errorObj) { this.setError(errorObj.code, errorObj.message, errorObj.type ?? DEFAULT_ERROR_TYPE) }
|
|
202
|
-
get errorCode() { return this._errorCode; }
|
|
203
|
-
set errorCode(code) { this.setError(code, this._errorMessage); }
|
|
204
|
-
get errorMessage() { return this._errorMessage; }
|
|
205
|
-
set errorMessage(msg) { this.setError(this._errorCode, msg); }
|
|
206
|
-
get errorType() { return this._errorType; }
|
|
207
|
-
get externalValue() { return this._externalValue; }
|
|
208
|
-
get format() { return this._fieldFormat; }
|
|
209
|
-
set format(format) { this.setAttr(attrs.fieldFormat, format); }
|
|
210
|
-
get hasChanged() { return this._hasChanged; }
|
|
211
|
-
set hasChanged(hasChanged) { this.setAttr(attrs.hasChanged, hasChanged); }
|
|
212
|
-
|
|
213
|
-
get info() { return this._fieldInfo; }
|
|
214
|
-
set info(newInfo: string) { this.setAttr(attrs.fieldInfo, newInfo); }
|
|
215
|
-
set intrinsicErrorMessage(message: string) { this.setAttr(attrs.intrinsicErrorMessage, message); }
|
|
216
|
-
get maxLength() { return (this._maxLength > 0) ? this._maxLength.toString() : ''; }
|
|
217
|
-
set maxLength(requiredMaxLength: any) { this.setAttr(attrs.maxLength, requiredMaxLength ? +requiredMaxLength : null); }
|
|
218
|
-
get maxValue() { return this._maxValue; }
|
|
219
|
-
|
|
220
|
-
set maxValue(inputMaxValue) {
|
|
221
|
-
let maxValue = inputMaxValue;
|
|
222
|
-
if (this._fieldType === this._formConfig.fieldTypes.date) {
|
|
223
|
-
maxValue = new Date(maxValue);
|
|
224
|
-
}
|
|
225
|
-
this.setAttr(attrs.maxValue, maxValue);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
get minLength() { return this._minLength; }
|
|
229
|
-
set minLength(requiredMinLength: number) {
|
|
230
|
-
this.setAttr(attrs.minLength, requiredMinLength ? +requiredMinLength : null);
|
|
231
|
-
}
|
|
232
|
-
get minValue() { return this._minValue; }
|
|
233
|
-
|
|
234
|
-
set minValue(inputMinValue) {
|
|
235
|
-
let minValue = inputMinValue;
|
|
236
|
-
if (this._fieldType === this._formConfig.fieldTypes.date) {
|
|
237
|
-
minValue = new Date(minValue);
|
|
238
|
-
}
|
|
239
|
-
this.setAttr(attrs.minValue, minValue);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
get name() { return this._fieldCode; }
|
|
243
|
-
|
|
244
|
-
get options(): FieldOption[] | null {
|
|
245
|
-
return this._fieldOptions?.map(option => {
|
|
246
|
-
const optionCopy: FieldOption = { ...option };
|
|
247
|
-
return optionCopy;
|
|
248
|
-
}) ?? [];
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
set options(newOptions) {
|
|
252
|
-
if ((!this._formConfig.captureTypesWithOptions.includes(this._captureType))
|
|
253
|
-
|| typeof newOptions === UNDEFINED || !newOptions
|
|
254
|
-
|| !Array.isArray(newOptions)) {
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
let fieldOptions = newOptions.map((option: any) => {
|
|
258
|
-
if (option.text !== undefined && option.text !== null
|
|
259
|
-
&& option.value !== undefined && option.value !== null) {
|
|
260
|
-
return { fieldOptionValue: option.text, fieldOptionId: option.value };
|
|
261
|
-
}
|
|
262
|
-
return option;
|
|
263
|
-
});
|
|
264
|
-
fieldOptions = (fieldOptions && Array.isArray(fieldOptions)
|
|
265
|
-
&& fieldOptions.length > 0) ? fieldOptions : [];
|
|
266
|
-
this.setAttr(attrs.fieldOptions, fieldOptions);
|
|
267
|
-
if (this._value) {
|
|
268
|
-
if (this._fieldType === this._formConfig.fieldTypes.array && Array.isArray(this._value)) {
|
|
269
|
-
const fieldValue = this._value?.filter(item =>
|
|
270
|
-
this._fieldOptions?.find(opt => opt.fieldOptionId === item)
|
|
271
|
-
);
|
|
272
|
-
this.setAttr(attrs.value, fieldValue);
|
|
273
|
-
} else {
|
|
274
|
-
const valInOptions = this._fieldOptions?.find(item => item.fieldOptionId === this._value);
|
|
275
|
-
if (!valInOptions) {
|
|
276
|
-
this._setValue('');
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
if (this._fieldRequired && this._fieldOptions?.length === 1 && this._value !== this._fieldOptions?.[0].fieldOptionId) {
|
|
281
|
-
this._setValue(this._fieldOptions?.[0].fieldOptionId);
|
|
282
|
-
this.notifyEditionFinish();
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
get optionText() { return this._fieldOptions?.find(item => item.fieldOptionId === this._value)?.fieldOptionValue ?? null; }
|
|
287
|
-
get outputOnly() { return this._outputOnly; }
|
|
288
|
-
set outputOnly(outputOnly) { this.setAttr(attrs.outputOnly, outputOnly); }
|
|
289
|
-
get required(): boolean { return this._fieldRequired; }
|
|
290
|
-
set required(required: boolean) { this.setAttr(attrs.fieldRequired, required ?? false); }
|
|
291
|
-
get title() { return this._fieldTitle; }
|
|
292
|
-
set title(title) { this.setAttr(attrs.fieldTitle, title?.toString() ?? ''); }
|
|
293
|
-
get tooltip() { return this._tooltipText; }
|
|
294
|
-
set tooltip(tooltip) { this.setAttr(attrs.tooltipText, tooltip); }
|
|
295
|
-
get type() { return this._fieldType; }
|
|
296
|
-
set type(fieldType) { this.setAttr(attrs.fieldType, fieldType); }
|
|
297
|
-
get onValidation() { return this._onValidation; }
|
|
298
|
-
get validating() { return this._onValidation; }
|
|
299
|
-
set validating(isValidating: boolean) { this.setAttr(attrs.onValidation, isValidating); }
|
|
300
|
-
get value() {
|
|
301
|
-
return (this._fieldType === this._formConfig.fieldTypes.boolean
|
|
302
|
-
|| this._fieldType === this._formConfig.fieldTypes.check) ? yn(this._value) : this._value;
|
|
303
|
-
}
|
|
304
|
-
get validateOnServer() { return this._validateOnServer; }
|
|
305
|
-
set validateOnServer(validateOnServer) { this.setAttr(attrs.validateOnServer, validateOnServer); }
|
|
306
|
-
get serverAction() { return this._validateOnServer; }
|
|
307
|
-
set serverAction(validateOnServer: boolean) { this.validateOnServer = validateOnServer; }
|
|
308
|
-
|
|
309
|
-
set value(newValue) { this._setValue(newValue); }
|
|
310
|
-
get visibleLabel() { return this._visibleLabel; }
|
|
311
|
-
set visibleLabel(visibleLabel: boolean) { this.setAttr(attrs.visibleLabel, visibleLabel); }
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* @deprecated Use value
|
|
315
|
-
*/
|
|
316
|
-
get fieldValue() { return this.value; }
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* @deprecated Use hasChanged
|
|
320
|
-
*/
|
|
321
|
-
changed(hasChanged = true) { this.hasChanged = hasChanged; }
|
|
322
|
-
|
|
323
|
-
clean() { this._setValue(this._defaultValue || ''); this.resetError(); }
|
|
324
|
-
focus() { this.setAttr(attrs.focus, true); }
|
|
325
|
-
getErrorCode() { return this.error.code; }
|
|
326
|
-
setErrorCode(code) { this.setError(code, this._errorMessage); }
|
|
327
|
-
getErrorMessage() { return this.error.message; }
|
|
328
|
-
setErrorMessage(msg) { this.setError(this._errorCode, msg); }
|
|
329
|
-
getRequired() { return this.required; }
|
|
330
|
-
hasError() { return this._errorCode !== NO_ERROR; }
|
|
331
|
-
hideLabel() { this.visibleLabel = false; }
|
|
332
|
-
resetError() { (this._errorCode !== NO_ERROR) && this.setError(NO_ERROR, null); }
|
|
333
|
-
setEditable(editable: boolean = true) { (editable) ? this.enable() : this.disable(); }
|
|
334
|
-
setValue(newValue, widgetUpdate = true) { this._setValue(newValue, widgetUpdate); }
|
|
335
|
-
showLabel() { this.visibleLabel = true; }
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* @deprecated Use code
|
|
339
|
-
*/
|
|
340
|
-
get fieldCode() { return this._fieldCode; }
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* @deprecated Use title
|
|
345
|
-
*/
|
|
346
|
-
setLabel(label) { this.title = label; }
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* @deprecated Use required
|
|
350
|
-
*/
|
|
351
|
-
setRequired(required: boolean) { this.required = required; }
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* @deprecated Use changed
|
|
355
|
-
*/
|
|
356
|
-
setChanged(hasChanged: boolean) { this.changed(hasChanged); }
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* @deprecated Use value
|
|
360
|
-
*/
|
|
361
|
-
getValue(): any { return this.value; }
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* @deprecated Use empty
|
|
365
|
-
*/
|
|
366
|
-
isEmpty(): boolean { return this.empty }
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* @deprecated Use error
|
|
370
|
-
*/
|
|
371
|
-
getError() { return this.error; }
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* @deprecated Use optionText
|
|
375
|
-
*/
|
|
376
|
-
getOptionText() { return this.optionText; }
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* @deprecated Use options
|
|
380
|
-
*/
|
|
381
|
-
getFieldOptions() { return this.options; }
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* @deprecated Use options
|
|
385
|
-
*/
|
|
386
|
-
setFieldOptions(newOptions) { return this.options = newOptions; }
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* @deprecated Use intrinsicErrorMessage
|
|
390
|
-
*/
|
|
391
|
-
setIntrinsicErrorMessage(message: string) { this.intrinsicErrorMessage = message; }
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* @deprecated Use maxValue
|
|
395
|
-
*/
|
|
396
|
-
setMaxValue(inputMaxValue) { this.maxValue = inputMaxValue; }
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* @deprecated Use minValue
|
|
400
|
-
*/
|
|
401
|
-
setMinValue(inputMinValue) { this.minValue = inputMinValue; }
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* @deprecated Use showLabel
|
|
405
|
-
*/
|
|
406
|
-
setVisibleLabel(visibleLabel: boolean) { this.visibleLabel = visibleLabel; }
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
notifyEditionPartial() {
|
|
410
|
-
this.resetError();
|
|
411
|
-
this._editionPartial.next({ code: this._fieldCode, intrinsicValidation: true });
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
triggerCustomEvent(eventName, eventData) {
|
|
415
|
-
this._customEvent.next({ code: this._fieldCode, eventName, eventData });
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
notifyEditionFinish() {
|
|
419
|
-
const fieldValue = this.value;
|
|
420
|
-
this.resetError();
|
|
421
|
-
const validationConfig = this._formConfig.fieldValidations?.[this._fieldType] ?? {};
|
|
422
|
-
const { type, validation } = validationConfig;
|
|
423
|
-
let message = validationConfig?.message;
|
|
424
|
-
let intrinsicValidation = true;
|
|
425
|
-
if (fieldValue && (validation || this._fieldFormat)) {
|
|
426
|
-
if (type === 'regexp') {
|
|
427
|
-
intrinsicValidation = (validation?.test(fieldValue) ?? true)
|
|
428
|
-
&& (this._fieldFormat?.test(fieldValue) ?? true);
|
|
429
|
-
} else if (type === 'function' && typeof validation === 'function') {
|
|
430
|
-
const { valid, message: customMessage } = validation(fieldValue, this);
|
|
431
|
-
intrinsicValidation = valid;
|
|
432
|
-
message = customMessage;
|
|
433
|
-
}
|
|
434
|
-
if (!intrinsicValidation) {
|
|
435
|
-
this.setError('99', message ?? this._intrinsicErrorMessage);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
if (intrinsicValidation && fieldValue && this._minValue && fieldValue < this._minValue) {
|
|
439
|
-
intrinsicValidation = false;
|
|
440
|
-
this.setError('99', 'Campo con valor inferior al mínimo');
|
|
441
|
-
}
|
|
442
|
-
if (intrinsicValidation && fieldValue && this._maxValue && fieldValue > this._maxValue) {
|
|
443
|
-
intrinsicValidation = false;
|
|
444
|
-
this.setError('99', 'Campo con valor superior al máximo');
|
|
445
|
-
}
|
|
446
|
-
if (intrinsicValidation && fieldValue && typeof fieldValue === 'string'
|
|
447
|
-
&& this._minLength && fieldValue?.length < this._minLength) {
|
|
448
|
-
intrinsicValidation = false;
|
|
449
|
-
this.setError('99', `Longitud de ${this._fieldTitle} debe ser de al menos ${this._minLength}`);
|
|
450
|
-
}
|
|
451
|
-
this._editionFinish.next({ code: this._fieldCode, intrinsicValidation });
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
notifyEditionDetailRequest(detail: any) {
|
|
455
|
-
const detailEvent: DetailEvent = { code: this._fieldCode, detail };
|
|
456
|
-
this._detailRequest.next(detailEvent);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
setError(code, message, type = DEFAULT_ERROR_TYPE) {
|
|
460
|
-
this.setAttr(attrs.errorCode, code ?? NO_ERROR);
|
|
461
|
-
this.setAttr(attrs.errorType, (this._errorCode === NO_ERROR) ? '' : type);
|
|
462
|
-
this.setAttr(attrs.errorMessage, message ?? '');
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
updateFromServer(fld) {
|
|
466
|
-
const fieldKeys = Object.keys(fld);
|
|
467
|
-
for (let index = 0; index < fieldKeys.length; index++) {
|
|
468
|
-
const attrName = fieldKeys[index];
|
|
469
|
-
const attrValue = fld[attrName];
|
|
470
|
-
if (directChanges.includes(attrName)) {
|
|
471
|
-
this[attrName] = attrValue;
|
|
472
|
-
} else {
|
|
473
|
-
(attrName === 'label') && (this.title = attrValue);
|
|
474
|
-
(attrName === 'labelVisible') && (this.visibleLabel = attrValue);
|
|
475
|
-
(attrName === 'editable') && this.setEditable(attrValue);
|
|
476
|
-
(attrName === 'visible') && this.setVisibility(attrValue);
|
|
477
|
-
(attrName === 'value') && (this._setValue(attrValue) && (this.hasChanged = false));
|
|
478
|
-
(attrName === 'fieldValue') && (this._setValue(attrValue) && (this.hasChanged = false));
|
|
479
|
-
(attrName === 'fieldOptions') && (this.options = attrValue);
|
|
480
|
-
(attrName === 'fieldTitle') && (this.title = attrValue);
|
|
481
|
-
(attrName === 'fieldTypeCode') && (this.type = attrValue);
|
|
482
|
-
(attrName === 'fieldType') && (this.type = attrValue);
|
|
483
|
-
(attrName === 'tooltipText') && (this.tooltip = attrValue);
|
|
484
|
-
(attrName === 'customAttributes') && (this.setCustomAttributes(attrValue));
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
private _setValue(newValue, widgetUpdate = true) {
|
|
490
|
-
if (typeof newValue === UNDEFINED) {
|
|
491
|
-
return true;
|
|
492
|
-
}
|
|
493
|
-
if (newValue === null && this.required) {
|
|
494
|
-
return true;
|
|
495
|
-
}
|
|
496
|
-
let newFinalValue;
|
|
497
|
-
if (this._fieldType === this._formConfig.fieldTypes.boolean
|
|
498
|
-
|| this._fieldType === this._formConfig.fieldTypes.check) {
|
|
499
|
-
newFinalValue = yn(newValue) ?? false;
|
|
500
|
-
} else if (this._fieldType === this._formConfig.fieldTypes.array
|
|
501
|
-
|| this._fieldType === this._formConfig.fieldTypes.map) {
|
|
502
|
-
if (newValue === null || newValue === '') {
|
|
503
|
-
newFinalValue = [];
|
|
504
|
-
} else if (Array.isArray(newValue)) {
|
|
505
|
-
newFinalValue = newValue;
|
|
506
|
-
} else {
|
|
507
|
-
newFinalValue = newValue.toString().split(',');
|
|
508
|
-
}
|
|
509
|
-
} else {
|
|
510
|
-
newFinalValue = newValue;
|
|
511
|
-
}
|
|
512
|
-
if (this._value !== newFinalValue) {
|
|
513
|
-
this._hasChanged = true;
|
|
514
|
-
if (widgetUpdate) {
|
|
515
|
-
this.setAttr(attrs.value, newFinalValue);
|
|
516
|
-
} else {
|
|
517
|
-
this._value = newFinalValue;
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
return true;
|
|
521
|
-
}
|
|
522
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export const NO_ERROR = '00';
|
|
2
|
-
export const HEADER = 'HEADER';
|
|
3
|
-
|
|
4
|
-
export const elementTypes = {
|
|
5
|
-
action: 'ACTION',
|
|
6
|
-
field: 'FIELD',
|
|
7
|
-
table: 'TABLE',
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const formActions = {
|
|
11
|
-
tableAction: 'TABLEACTION',
|
|
12
|
-
getData: 'GETDATA',
|
|
13
|
-
getTableData: 'GETTABLEDATA',
|
|
14
|
-
validate: 'VALIDATE',
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const operators = {
|
|
18
|
-
G: 'G',
|
|
19
|
-
L: 'L',
|
|
20
|
-
GE: 'GE',
|
|
21
|
-
LE: 'LE',
|
|
22
|
-
EQ: 'EQ',
|
|
23
|
-
NEQ: 'NEQ',
|
|
24
|
-
HAS: 'HAS',
|
|
25
|
-
NOTHAS: 'NOTHAS',
|
|
26
|
-
BETWEEN: 'BETWEEN',
|
|
27
|
-
IN: 'IN',
|
|
28
|
-
};
|