tuain-ng-forms-lib 14.4.93 → 14.4.95

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.
Files changed (108) hide show
  1. package/esm2020/lib/classes/forms/action.mjs +36 -0
  2. package/esm2020/lib/classes/forms/element.mjs +26 -0
  3. package/esm2020/lib/classes/forms/field.mjs +445 -0
  4. package/esm2020/lib/classes/forms/form.constants.mjs +26 -0
  5. package/esm2020/lib/classes/forms/form.mjs +431 -0
  6. package/esm2020/lib/classes/forms/piece-propagate.mjs +37 -0
  7. package/esm2020/lib/classes/forms/piece.mjs +95 -0
  8. package/esm2020/lib/classes/forms/section.mjs +138 -0
  9. package/esm2020/lib/classes/forms/subsection.mjs +81 -0
  10. package/esm2020/lib/classes/forms/table/action.mjs +18 -0
  11. package/esm2020/lib/classes/forms/table/column.mjs +74 -0
  12. package/esm2020/lib/classes/forms/table/row-data.mjs +116 -0
  13. package/esm2020/lib/classes/forms/table/table.mjs +416 -0
  14. package/esm2020/lib/components/elements/action.component.mjs +71 -0
  15. package/esm2020/lib/components/elements/field.component.mjs +81 -0
  16. package/esm2020/lib/components/elements/layout/element.component.mjs +20 -0
  17. package/esm2020/lib/components/elements/layout/form-error.component.mjs +20 -0
  18. package/esm2020/lib/components/elements/layout/form-header.component.mjs +31 -0
  19. package/esm2020/lib/components/elements/layout/piece.component.mjs +39 -0
  20. package/esm2020/lib/components/elements/layout/section.component.mjs +37 -0
  21. package/esm2020/lib/components/elements/layout/sub-section.component.mjs +37 -0
  22. package/esm2020/lib/components/elements/tables/table-record-action.component.mjs +56 -0
  23. package/esm2020/lib/components/elements/tables/table-record-field.component.mjs +30 -0
  24. package/esm2020/lib/components/elements/tables/table.component.mjs +89 -0
  25. package/esm2020/lib/components/forms/basic-form.mjs +1514 -0
  26. package/esm2020/lib/services/event-manager.service.mjs +18 -0
  27. package/esm2020/lib/services/file-manager.service.mjs +6 -0
  28. package/esm2020/lib/services/form-manager.service.mjs +80 -0
  29. package/esm2020/lib/tuain-ng-forms-lib.module.mjs +71 -0
  30. package/esm2020/public-api.mjs +19 -0
  31. package/esm2020/tuain-ng-forms-lib.mjs +5 -0
  32. package/fesm2015/tuain-ng-forms-lib.mjs +4259 -0
  33. package/fesm2015/tuain-ng-forms-lib.mjs.map +1 -0
  34. package/fesm2020/tuain-ng-forms-lib.mjs +4074 -0
  35. package/fesm2020/tuain-ng-forms-lib.mjs.map +1 -0
  36. package/lib/classes/forms/action.d.ts +22 -0
  37. package/lib/classes/forms/element.d.ts +17 -0
  38. package/lib/classes/forms/field.d.ts +205 -0
  39. package/lib/classes/forms/form.constants.d.ts +25 -0
  40. package/lib/classes/forms/form.d.ts +137 -0
  41. package/lib/classes/forms/piece-propagate.d.ts +13 -0
  42. package/lib/classes/forms/piece.d.ts +41 -0
  43. package/lib/classes/forms/section.d.ts +32 -0
  44. package/lib/classes/forms/subsection.d.ts +24 -0
  45. package/lib/classes/forms/table/action.d.ts +15 -0
  46. package/lib/classes/forms/table/column.d.ts +33 -0
  47. package/lib/classes/forms/table/row-data.d.ts +14 -0
  48. package/lib/classes/forms/table/table.d.ts +100 -0
  49. package/lib/components/elements/action.component.d.ts +17 -0
  50. package/lib/components/elements/field.component.d.ts +38 -0
  51. package/lib/components/elements/layout/element.component.d.ts +9 -0
  52. package/lib/components/elements/layout/form-error.component.d.ts +8 -0
  53. package/lib/components/elements/layout/form-header.component.d.ts +12 -0
  54. package/lib/components/elements/layout/piece.component.d.ts +12 -0
  55. package/lib/components/elements/layout/section.component.d.ts +11 -0
  56. package/lib/components/elements/layout/sub-section.component.d.ts +11 -0
  57. package/lib/components/elements/tables/table-record-action.component.d.ts +16 -0
  58. package/lib/components/elements/tables/table-record-field.component.d.ts +12 -0
  59. package/lib/components/elements/tables/table.component.d.ts +35 -0
  60. package/lib/components/forms/basic-form.d.ts +353 -0
  61. package/lib/services/event-manager.service.d.ts +9 -0
  62. package/lib/services/file-manager.service.d.ts +5 -0
  63. package/lib/services/form-manager.service.d.ts +28 -0
  64. package/lib/tuain-ng-forms-lib.module.d.ts +20 -0
  65. package/package.json +24 -6
  66. package/{src/public-api.ts → public-api.d.ts} +0 -5
  67. package/tuain-ng-forms-lib.d.ts +5 -0
  68. package/.browserslistrc +0 -16
  69. package/.yarn/cache/nanoid-npm-4.0.0-924f5c6312-7d5946df5c.zip +0 -0
  70. package/.yarn/cache/tslib-npm-2.4.1-36f0ed04db-19480d6e03.zip +0 -0
  71. package/.yarn/cache/yn-npm-5.0.0-b001dab23c-f0ec7710d3.zip +0 -0
  72. package/.yarn/install-state.gz +0 -0
  73. package/karma.conf.js +0 -44
  74. package/ng-package.json +0 -11
  75. package/src/lib/classes/forms/action.ts +0 -56
  76. package/src/lib/classes/forms/element.ts +0 -29
  77. package/src/lib/classes/forms/field.ts +0 -500
  78. package/src/lib/classes/forms/form.constants.ts +0 -28
  79. package/src/lib/classes/forms/form.ts +0 -508
  80. package/src/lib/classes/forms/piece-propagate.ts +0 -46
  81. package/src/lib/classes/forms/piece.ts +0 -122
  82. package/src/lib/classes/forms/section.ts +0 -152
  83. package/src/lib/classes/forms/subsection.ts +0 -90
  84. package/src/lib/classes/forms/table/action.ts +0 -32
  85. package/src/lib/classes/forms/table/column.ts +0 -94
  86. package/src/lib/classes/forms/table/row-data.ts +0 -121
  87. package/src/lib/classes/forms/table/table.ts +0 -478
  88. package/src/lib/components/elements/action.component.ts +0 -59
  89. package/src/lib/components/elements/field.component.ts +0 -92
  90. package/src/lib/components/elements/layout/element.component.ts +0 -13
  91. package/src/lib/components/elements/layout/form-error.component.ts +0 -11
  92. package/src/lib/components/elements/layout/form-header.component.ts +0 -17
  93. package/src/lib/components/elements/layout/piece.component.ts +0 -34
  94. package/src/lib/components/elements/layout/section.component.ts +0 -31
  95. package/src/lib/components/elements/layout/sub-section.component.ts +0 -31
  96. package/src/lib/components/elements/tables/table-record-action.component.ts +0 -50
  97. package/src/lib/components/elements/tables/table-record-field.component.ts +0 -20
  98. package/src/lib/components/elements/tables/table.component.ts +0 -86
  99. package/src/lib/components/forms/basic-form.ts +0 -1588
  100. package/src/lib/services/event-manager.service.ts +0 -21
  101. package/src/lib/services/file-manager.service.ts +0 -6
  102. package/src/lib/services/form-manager.service.ts +0 -89
  103. package/src/lib/services/icon-dictionary.service.ts +0 -159
  104. package/src/lib/tuain-ng-forms-lib.module.ts +0 -40
  105. package/src/test.ts +0 -27
  106. package/tsconfig.lib.json +0 -15
  107. package/tsconfig.lib.prod.json +0 -10
  108. package/tsconfig.spec.json +0 -17
@@ -1,7 +1,3 @@
1
- /*
2
- * Public API Surface of tuain-ng-forms-lib
3
- */
4
-
5
1
  export * from './lib/components/elements/action.component';
6
2
  export * from './lib/components/elements/field.component';
7
3
  export * from './lib/components/elements/layout/element.component';
@@ -17,4 +13,3 @@ export * from './lib/services/event-manager.service';
17
13
  export * from './lib/services/form-manager.service';
18
14
  export * from './lib/services/file-manager.service';
19
15
  export * from './lib/tuain-ng-forms-lib.module';
20
-
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ /// <amd-module name="tuain-ng-forms-lib" />
5
+ export * from './public-api';
package/.browserslistrc DELETED
@@ -1,16 +0,0 @@
1
- # This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2
- # For additional information regarding the format and rule options, please see:
3
- # https://github.com/browserslist/browserslist#queries
4
-
5
- # For the full list of supported browsers by the Angular framework, please see:
6
- # https://angular.io/guide/browser-support
7
-
8
- # You can see what browsers were selected by your queries by running:
9
- # npx browserslist
10
-
11
- last 1 Chrome version
12
- last 1 Firefox version
13
- last 2 Edge major versions
14
- # last 2 Safari major versions
15
- last 2 iOS major versions
16
- Firefox ESR
Binary file
package/karma.conf.js DELETED
@@ -1,44 +0,0 @@
1
- // Karma configuration file, see link for more information
2
- // https://karma-runner.github.io/1.0/config/configuration-file.html
3
-
4
- module.exports = function (config) {
5
- config.set({
6
- basePath: '',
7
- frameworks: ['jasmine', '@angular-devkit/build-angular'],
8
- plugins: [
9
- require('karma-jasmine'),
10
- require('karma-chrome-launcher'),
11
- require('karma-jasmine-html-reporter'),
12
- require('karma-coverage'),
13
- require('@angular-devkit/build-angular/plugins/karma')
14
- ],
15
- client: {
16
- jasmine: {
17
- // you can add configuration options for Jasmine here
18
- // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19
- // for example, you can disable the random execution with `random: false`
20
- // or set a specific seed with `seed: 4321`
21
- },
22
- clearContext: false // leave Jasmine Spec Runner output visible in browser
23
- },
24
- jasmineHtmlReporter: {
25
- suppressAll: true // removes the duplicated traces
26
- },
27
- coverageReporter: {
28
- dir: require('path').join(__dirname, '../../coverage/tuain-ng-forms-lib'),
29
- subdir: '.',
30
- reporters: [
31
- { type: 'html' },
32
- { type: 'text-summary' }
33
- ]
34
- },
35
- reporters: ['progress', 'kjhtml'],
36
- port: 9876,
37
- colors: true,
38
- logLevel: config.LOG_INFO,
39
- autoWatch: true,
40
- browsers: ['Chrome'],
41
- singleRun: false,
42
- restartOnFileChange: true
43
- });
44
- };
package/ng-package.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
- "dest": "../../dist/tuain-ng-forms-lib",
4
- "lib": {
5
- "entryFile": "src/public-api.ts"
6
- },
7
- "allowedNonPeerDependencies": [
8
- "nanoid",
9
- "yn"
10
- ]
11
- }
@@ -1,56 +0,0 @@
1
- import { Subject } from 'rxjs';
2
- import { elementTypes } from './form.constants';
3
- import { FormElement } from './element';
4
-
5
- const HEADER = 'HEADER';
6
-
7
- export class FormAction extends FormElement {
8
- private readonly _actionActivated = new Subject<string>();
9
-
10
- inProgress = false;
11
- newState: string;
12
- backend: boolean;
13
-
14
- actionCode: string;
15
- actionName: string;
16
- iconName: string;
17
-
18
- restrictedOnField: string;
19
- restrictedOnOperator: string;
20
- restrictedOnValue: string;
21
- customValidation: any;
22
-
23
- constructor(actionDefinition, formConfig) {
24
- super(actionDefinition, formConfig);
25
- this.propagationCustomAttributes = this._formConfig?.propagationCustomAttributes?.actions ?? [];
26
- this.elementType = elementTypes.action;
27
- this.actionCode = actionDefinition.actionCode ? actionDefinition.actionCode.toString() : '';
28
- this.actionName = actionDefinition.actionTitle;
29
- this.iconName = actionDefinition.iconName || this.actionCode;
30
- this.setCustomAttribute('location', actionDefinition.position || HEADER);
31
- this.backend = actionDefinition?.serverAction ?? false;
32
- this.newState = actionDefinition?.newState;
33
-
34
- this.restrictedOnField = actionDefinition.fieldRestrictedCode ? actionDefinition.fieldRestrictedCode.toString() : '';
35
- this.restrictedOnOperator = actionDefinition.operatorRestricted || '';
36
- this.restrictedOnValue = actionDefinition.valueRestricted ?? '';
37
- this.customValidation = () => true;
38
- }
39
-
40
- get actionActivated() { return this._actionActivated; }
41
-
42
- start() { this.inProgress = true; }
43
- stop() { this.inProgress = false; }
44
-
45
- notifyActivation() { this._actionActivated.next(this.actionCode); }
46
-
47
- updateFromServer(receivedAction) {
48
- for (const propertyName in receivedAction) {
49
- if (propertyName !== 'actionCode' && propertyName !== 'actionId') {
50
- this[propertyName] = receivedAction[propertyName];
51
- }
52
- }
53
- }
54
-
55
- setCustomValidation(callback) { this.customValidation = () => callback(); }
56
- }
@@ -1,29 +0,0 @@
1
- import { FormPiecePropagate } from './piece-propagate';
2
- import { elementTypes } from './form.constants';
3
- export class FormElement extends FormPiecePropagate {
4
- elementType: string | null = null;;
5
-
6
- constructor(elementDefinition: any, formConfig: any) {
7
- super(elementDefinition, formConfig);
8
- }
9
-
10
- setAttr(attr: any, value: any) {
11
- const { name: attrName, propagate: name } = attr;
12
- this[attrName] = value;
13
- name && this.propagateAttribute(name, value);
14
- }
15
-
16
- isField(): boolean { return this.elementType === elementTypes.field; }
17
- isAction(): boolean { return this.elementType === elementTypes.action; }
18
- isTable(): boolean { return this.elementType === elementTypes.table; }
19
-
20
- /**
21
- * @deprecated Utilizar viewOnState
22
- */
23
- supportState(state: string): boolean { return this.viewOnState(state); }
24
-
25
- /**
26
- * @deprecated Utilizar viewOnState
27
- */
28
- supportMode(state: string): boolean { return this.viewOnState(state); }
29
- }
@@ -1,500 +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',
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
- _tooltipText: { name: '_tooltipText', propagate: 'tooltip' },
47
- _validateOnServer: { name: '_validateOnServer', propagate: 'validateOnServer' },
48
- _value: { name: '_value', propagate: 'value' },
49
- _visibleLabel: { name: '_visibleLabel', propagate: 'visibleLabel' },
50
- };
51
-
52
- export interface DetailEvent {
53
- code: string;
54
- detail: any;
55
- }
56
-
57
- export interface FieldOption {
58
- fieldOptionValue: string;
59
- fieldOptionId: string;
60
- }
61
-
62
- export class FieldDescriptor extends FormElement {
63
- private readonly _editionFinish = new Subject<any>();
64
- private readonly _editionPartial = new Subject<any>();
65
- private readonly _detailRequest = new Subject<DetailEvent>();
66
-
67
- private _errorType: string = '';
68
- private _errorCode: string = '';
69
- private _errorMessage: string = '';
70
- private _fieldCode: string = '';
71
- private _intrinsicErrorMessage: string = '';
72
- private _minValue: any;
73
- private _maxValue: any;
74
- private _maxLength: number = 0;
75
- private _minLength: number = 0;
76
- private _focus: boolean = false;
77
- private _onValidation: boolean = false;
78
- private _validateOnServer: boolean = false;
79
- private _value: any;
80
- private _visibleLabel: boolean = false;
81
-
82
- private _captureType: string = '';
83
- private _defaultValue: string = '';
84
- private _defaultEditable: boolean = false;
85
- private _externalValue: any;
86
- private _fieldAlignment: string = '';
87
- private _fieldInfo: string = '';
88
- private _fieldRequired: boolean = false;
89
- private _fieldTitle: string = '';
90
- private _fieldType: string = '';
91
- private _fieldFormat: RegExp | null = null;
92
- private _fieldOptions: FieldOption[] | null = null;
93
- private _hasChanged: boolean = false;
94
- private _outputOnly: boolean = false;
95
- private _tooltipText: string = '';
96
-
97
- constructor(inputFieldReceived, formConfig) {
98
- super(inputFieldReceived, formConfig);
99
- this.propagationCustomAttributes = this._formConfig?.propagationCustomAttributes?.fields ?? [];
100
- this.elementType = elementTypes.field;
101
- const fld = (inputFieldReceived) ? inputFieldReceived : {};
102
- this.setAttr(attrs._fieldCode, fld.fieldCode);
103
- this.title = fld.fieldTitle ?? this._fieldCode;
104
- this.type = fld.fieldTypeCode;
105
- this.captureType = fld.captureType ?? DEFAULT_CAPTURE_TYPE;
106
-
107
- const defaultValue = fld.defaultValue ?? null;
108
- if (this._fieldType === this._formConfig.fieldTypes.boolean) {
109
- this.defaultValue = defaultValue ?? false;
110
- } else {
111
- this.defaultValue = defaultValue;
112
- }
113
- const defaultTypeAlignment = (this._formConfig.tableFieldStyles[this._fieldType] != null)
114
- ? this._formConfig.tableFieldStyles[this._fieldType]['text-align'] : DEFAULT_ALIGNMENT;
115
- const fieldAlignment = (fld.alignment != null) ? fld.alignment.toLowerCase() : defaultTypeAlignment;
116
- this.alignment = fieldAlignment;
117
- this.info = fld.info || '';
118
- let fieldFormat;
119
- try {
120
- fieldFormat = (fld.format) ? new RegExp(fld.format) : null;
121
- } catch (e) {
122
- fieldFormat = null;
123
- }
124
- this.format = fieldFormat;
125
- this.validateOnServer = fld.serverAction ?? false;
126
- this.tooltip = fld.tooltip || '';
127
- this.defaultEditable = this.enabled;
128
- this.required = fld.required ?? false;
129
- this.outputOnly = fld.outputOnly ?? false;
130
- this.maxLength = fld.maxLength || (this._captureType === 'TEXTAREA' ? BIG_MAX_LENGTH : STD_MAX_LENGTH);
131
- this.intrinsicErrorMessage = this._formConfig?.fieldValidations?.[this._fieldType]?.message
132
- ?? this._formConfig?.fieldValidations?.DEFAULT?.message ?? '';
133
-
134
- this.setError(fld.errorCode, fld.errorMessage, fld.errorType ?? DEFAULT_ERROR_TYPE);
135
- this.setEditable(fld.editable ?? true);
136
- this.visibleLabel = fld.visibleLabel ?? true;
137
- this.setVisibility(fld.visible);
138
- this.options = fld.fieldOptions;
139
- this._setValue(fld.fieldValue ?? this._defaultValue ?? '');
140
- }
141
-
142
- get alignment() { return this._fieldAlignment; }
143
- set alignment(alignment) { this.setAttr(attrs._fieldAlignment, alignment); }
144
- get backend() { return this._validateOnServer; }
145
-
146
- get captureType() { return this._captureType; }
147
- set captureType(captureType) { this.setAttr(attrs._captureType, captureType); }
148
- get code() { return this._fieldCode; }
149
- get fieldCode() { return this._fieldCode; }
150
- get defaultValue() { return this._defaultValue; }
151
- set defaultValue(defaultValue) { this.setAttr(attrs._defaultValue, defaultValue); }
152
- get defaultEditable() { return this._defaultEditable; }
153
- set defaultEditable(editable) { this.setAttr(attrs._defaultEditable, editable); }
154
- get detailRequest() { return this._detailRequest; }
155
- get editionFinish() { return this._editionFinish; }
156
- get editionPartial() { return this._editionPartial; }
157
-
158
- get empty(): boolean {
159
- const fieldCurrentValue = this.value;
160
- if (fieldCurrentValue === undefined || fieldCurrentValue === null) {
161
- return true;
162
- }
163
- if (this._fieldType === this._formConfig.fieldTypes.array
164
- && Array.isArray(fieldCurrentValue) && fieldCurrentValue.length === 0) {
165
- return true;
166
- };
167
- if (this._fieldType === this._formConfig.fieldTypes.phone) {
168
- if (!Array.isArray(fieldCurrentValue)) {
169
- return true;
170
- }
171
- if (fieldCurrentValue.length !== 2 || !fieldCurrentValue[0] || !fieldCurrentValue[1]) {
172
- return true;
173
- }
174
- return false;
175
- };
176
- return fieldCurrentValue === '';
177
- }
178
-
179
-
180
-
181
- get error() { return { type: this._errorType, code: this._errorCode, message: this._errorMessage }; }
182
- set error(errorObj) { this.setError(errorObj.code, errorObj.message, errorObj.type ?? DEFAULT_ERROR_TYPE) }
183
- get errorCode() { return this._errorCode; }
184
- set errorCode(code) { this.setError(code, this._errorMessage); }
185
- get errorMessage() { return this._errorMessage; }
186
- set errorMessage(msg) { this.setError(this._errorCode, msg); }
187
- get errorType() { return this._errorType; }
188
- get externalValue() { return this._externalValue; }
189
- get format() { return this._fieldFormat; }
190
- set format(format) { this.setAttr(attrs._fieldFormat, format); }
191
- get hasChanged() { return this._hasChanged; }
192
- set hasChanged(hasChanged) { this.setAttr(attrs._hasChanged, hasChanged); }
193
-
194
- get info() { return this._fieldInfo; }
195
- set info(newInfo: string) { this.setAttr(attrs._fieldInfo, newInfo); }
196
- set intrinsicErrorMessage(message: string) { this.setAttr(attrs._intrinsicErrorMessage, message); }
197
- get maxLength() { return (this._maxLength > 0) ? this._maxLength.toString() : ''; }
198
- set maxLength(requiredMaxLength: any) { this.setAttr(attrs._maxLength, requiredMaxLength ? +requiredMaxLength : null); }
199
- get maxValue() { return this._maxValue; }
200
-
201
- set maxValue(inputMaxValue) {
202
- let maxValue = inputMaxValue;
203
- if (this._fieldType === this._formConfig.fieldTypes.date) {
204
- maxValue = new Date(maxValue);
205
- }
206
- this.setAttr(attrs._maxValue, maxValue);
207
- }
208
-
209
- get minLength() { return this._minLength; }
210
- set minLength(requiredMinLength: number) { this.setAttr(attrs._minLength, requiredMinLength ? +requiredMinLength : null); }
211
- get minValue() { return this._minValue; }
212
-
213
- set minValue(inputMinValue) {
214
- let minValue = inputMinValue;
215
- if (this._fieldType === this._formConfig.fieldTypes.date) {
216
- minValue = new Date(minValue);
217
- }
218
- this.setAttr(attrs._minValue, minValue);
219
- }
220
-
221
- get name() { return this._fieldCode; }
222
-
223
- get options(): FieldOption[] | null {
224
- return this._fieldOptions?.map(option => {
225
- const optionCopy: FieldOption = { ...option };
226
- return optionCopy;
227
- }) ?? null;
228
- }
229
-
230
- set options(newOptions) {
231
- if ((!this._formConfig.captureTypesWithOptions.includes(this._captureType))
232
- || typeof newOptions === UNDEFINED || !newOptions
233
- || !Array.isArray(newOptions)) {
234
- return;
235
- }
236
- let fieldOptions = newOptions.map((option: any) => {
237
- if (option.text !== undefined && option.text !== null
238
- && option.value !== undefined && option.value !== null) {
239
- return { fieldOptionValue: option.text, fieldOptionId: option.value };
240
- }
241
- return option;
242
- });
243
- fieldOptions = (fieldOptions && Array.isArray(fieldOptions)
244
- && fieldOptions.length > 0) ? fieldOptions : [];
245
- this.setAttr(attrs._fieldOptions, fieldOptions);
246
- if (this._value) {
247
- if (this._fieldType === this._formConfig.fieldTypes.array && Array.isArray(this._value)) {
248
- const fieldValue = this._value?.filter(item =>
249
- this._fieldOptions?.find(opt => opt.fieldOptionId === item)
250
- );
251
- this.setAttr(attrs._value, fieldValue);
252
- } else {
253
- const valInOptions = this._fieldOptions?.find(item => item.fieldOptionId === this._value);
254
- if (!valInOptions) {
255
- this._setValue('');
256
- }
257
- }
258
- }
259
- if (this._fieldRequired && this._fieldOptions?.length === 1 && this._value !== this._fieldOptions?.[0].fieldOptionId) {
260
- this._setValue(this._fieldOptions?.[0].fieldOptionId);
261
- this.notifyEditionFinish();
262
- }
263
- }
264
-
265
- get optionText() { return this._fieldOptions?.find(item => item.fieldOptionId === this._value)?.fieldOptionValue ?? null; }
266
- get outputOnly() { return this._outputOnly; }
267
- set outputOnly(outputOnly) { this.setAttr(attrs._outputOnly, outputOnly); }
268
- get required(): boolean { return this._fieldRequired; }
269
- set required(required: boolean) { this.setAttr(attrs._fieldRequired, required ?? false); }
270
- get title() { return this._fieldTitle; }
271
- set title(title) { this.setAttr(attrs._fieldTitle, title?.toString() ?? ''); }
272
- get tooltip() { return this._tooltipText; }
273
- set tooltip(tooltip) { this.setAttr(attrs._tooltipText, tooltip); }
274
- get type() { return this._fieldType; }
275
- set type(fieldType) { this.setAttr(attrs._fieldType, fieldType); }
276
- get validating() { return this._onValidation; }
277
- set validating(isValidating: boolean) { this.setAttr(attrs._onValidation, isValidating); }
278
- get value() {
279
- return (this._fieldType === this._formConfig.fieldTypes.boolean
280
- || this._fieldType === this._formConfig.fieldTypes.check) ? yn(this._value) : this._value;
281
- }
282
- get validateOnServer() { return this._validateOnServer; }
283
- set validateOnServer(validateOnServer) { this.setAttr(attrs._validateOnServer, validateOnServer); }
284
- get serverAction() { return this._validateOnServer; }
285
- set serverAction(validateOnServer: boolean) { this.validateOnServer = validateOnServer; }
286
-
287
- set value(newValue) { this._setValue(newValue); }
288
- get visibleLabel() { return this._visibleLabel; }
289
- set visibleLabel(visibleLabel: boolean) { this.setAttr(attrs._visibleLabel, visibleLabel); }
290
-
291
- /**
292
- * @deprecated Use options
293
- */
294
- get fieldOptions() { return this._fieldOptions; }
295
-
296
- /**
297
- * @deprecated Use options
298
- */
299
- set fieldOptions(options) { this.options = options; }
300
-
301
- /**
302
- * @deprecated Use value
303
- */
304
- get fieldValue() { return this.value; }
305
-
306
- /**
307
- * @deprecated Use hasChanged
308
- */
309
- changed(hasChanged = true) { this.hasChanged = hasChanged; }
310
-
311
- clean() { this._setValue(this._defaultValue || ''); this.resetError(); }
312
- focus() { this.setAttr(attrs._focus, true); }
313
- getErrorCode() { return this.error.code; }
314
- setErrorCode(code) { this.setError(code, this._errorMessage); }
315
- getErrorMessage() { return this.error.message; }
316
- setErrorMessage(msg) { this.setError(this._errorCode, msg); }
317
- getRequired() { return this.required; }
318
- hasError() { return this._errorCode !== NO_ERROR; }
319
- hideLabel() { this.visibleLabel = false; }
320
- resetError() { (this._errorCode !== NO_ERROR) && this.setError(NO_ERROR, null); }
321
- setEditable(editable: boolean = true) { (editable) ? this.enable() : this.disable(); }
322
- setValue(newValue, widgetUpdate = true) { this._setValue(newValue, widgetUpdate); }
323
- showLabel() { this.visibleLabel = true; }
324
-
325
- /**
326
- * @deprecated Use title
327
- */
328
- setLabel(label) { this.title = label; }
329
-
330
- /**
331
- * @deprecated Use required
332
- */
333
- setRequired(required: boolean) { this.required = required; }
334
-
335
- /**
336
- * @deprecated Use changed
337
- */
338
- setChanged(hasChanged: boolean) { this.changed(hasChanged); }
339
-
340
- /**
341
- * @deprecated Use value
342
- */
343
- getValue(): any { return this.value; }
344
-
345
- /**
346
- * @deprecated Use empty
347
- */
348
- isEmpty(): boolean { return this.empty }
349
-
350
- /**
351
- * @deprecated Use error
352
- */
353
- getError() { return this.error; }
354
-
355
- /**
356
- * @deprecated Use optionText
357
- */
358
- getOptionText() { return this.optionText; }
359
-
360
- /**
361
- * @deprecated Use options
362
- */
363
- getFieldOptions() { return this.options; }
364
-
365
- /**
366
- * @deprecated Use options
367
- */
368
- setFieldOptions(newOptions) { return this.options = newOptions; }
369
-
370
- /**
371
- * @deprecated Use intrinsicErrorMessage
372
- */
373
- setIntrinsicErrorMessage(message: string) { this.intrinsicErrorMessage = message; }
374
-
375
- /**
376
- * @deprecated Use maxValue
377
- */
378
- setMaxValue(inputMaxValue) { this.maxValue = inputMaxValue; }
379
-
380
- /**
381
- * @deprecated Use minValue
382
- */
383
- setMinValue(inputMinValue) { this.minValue = inputMinValue; }
384
-
385
- /**
386
- * @deprecated Use showLabel
387
- */
388
- setVisibleLabel(visibleLabel: boolean) { this.visibleLabel = visibleLabel; }
389
-
390
-
391
- notifyEditionPartial() {
392
- this.resetError();
393
- this._editionPartial.next({ code: this._fieldCode, intrinsicValidation: true });
394
- }
395
-
396
- notifyEditionFinish() {
397
- const fieldValue = this.value;
398
- this.resetError();
399
- const validationConfig = this._formConfig.fieldValidations?.[this._fieldType] ?? {};
400
- const { type, validation } = validationConfig;
401
- let message = validationConfig?.message;
402
- let intrinsicValidation = true;
403
- if (fieldValue && (validation || this._fieldFormat)) {
404
- if (type === 'regexp') {
405
- intrinsicValidation = (validation?.test(fieldValue) ?? true)
406
- && (this._fieldFormat?.test(fieldValue) ?? true);
407
- } else if (type === 'function' && typeof validation === 'function') {
408
- const { valid, message: customMessage } = validation(fieldValue, this);
409
- intrinsicValidation = valid;
410
- message = customMessage;
411
- }
412
- if (!intrinsicValidation) {
413
- this.setError('99', message ?? this._intrinsicErrorMessage);
414
- }
415
- }
416
- if (intrinsicValidation && fieldValue && this._minValue && fieldValue < this._minValue) {
417
- intrinsicValidation = false;
418
- this.setError('99', 'Campo con valor inferior al mínimo');
419
- }
420
- if (intrinsicValidation && fieldValue && this._maxValue && fieldValue > this._maxValue) {
421
- intrinsicValidation = false;
422
- this.setError('99', 'Campo con valor superior al máximo');
423
- }
424
- if (intrinsicValidation && fieldValue && typeof fieldValue === 'string'
425
- && this._minLength && fieldValue?.length < this._minLength) {
426
- intrinsicValidation = false;
427
- this.setError('99', `Longitud de ${this._fieldTitle} debe ser de al menos ${this._minLength}`);
428
- }
429
- this._editionFinish.next({ code: this._fieldCode, intrinsicValidation });
430
- }
431
-
432
- notifyEditionDetailRequest(detail: any) {
433
- const detailEvent: DetailEvent = { code: this._fieldCode, detail };
434
- this._detailRequest.next(detailEvent);
435
- }
436
-
437
- setError(code, message, type = DEFAULT_ERROR_TYPE) {
438
- this.setAttr(attrs._errorCode, code ?? NO_ERROR);
439
- this.setAttr(attrs._errorType, (this._errorCode === NO_ERROR) ? '' : type);
440
- this.setAttr(attrs._errorMessage, message ?? '');
441
- }
442
-
443
- updateFromServer(fld) {
444
- const fieldKeys = Object.keys(fld);
445
- for (let index = 0; index < fieldKeys.length; index++) {
446
- const attrName = fieldKeys[index];
447
- const attrValue = fld[attrName];
448
- if (directChanges.includes(attrName)) {
449
- this[attrName] = attrValue;
450
- } else {
451
- (attrName === 'label') && (this.title = attrValue);
452
- (attrName === 'labelVisible') && (this.visibleLabel = attrValue);
453
- (attrName === 'editable') && this.setEditable(attrValue);
454
- (attrName === 'visible') && this.setVisibility(attrValue);
455
- (attrName === 'value') && (this._setValue(attrValue) && (this.hasChanged = false));
456
- (attrName === 'fieldValue') && (this._setValue(attrValue) && (this.hasChanged = false));
457
-
458
- (attrName === 'fieldOptions') && (this.options = attrValue);
459
- (attrName === 'fieldTitle') && (this.title = attrValue);
460
- (attrName === 'fieldTypeCode') && (this.type = attrValue);
461
- (attrName === 'fieldType') && (this.type = attrValue);
462
- (attrName === 'tooltipText') && (this.tooltip = attrValue);
463
- }
464
- }
465
- }
466
-
467
- private _setValue(newValue, widgetUpdate = true) {
468
- if (typeof newValue === UNDEFINED) {
469
- return true;
470
- }
471
- if (newValue === null && this.required) {
472
- return true;
473
- }
474
- let newFinalValue;
475
- if (this._fieldType === this._formConfig.fieldTypes.boolean
476
- || this._fieldType === this._formConfig.fieldTypes.check) {
477
- newFinalValue = yn(newValue) ?? false;
478
- } else if (this._fieldType === this._formConfig.fieldTypes.array
479
- || this._fieldType === this._formConfig.fieldTypes.map) {
480
- if (newValue === null || newValue === '') {
481
- newFinalValue = [];
482
- } else if (Array.isArray(newValue)) {
483
- newFinalValue = newValue;
484
- } else {
485
- newFinalValue = newValue.toString().split(',');
486
- }
487
- } else {
488
- newFinalValue = newValue;
489
- }
490
- if (this._value !== newFinalValue) {
491
- this.hasChanged = true;
492
- if (widgetUpdate) {
493
- this.setAttr(attrs._value, newFinalValue);
494
- } else {
495
- this._value = newFinalValue;
496
- }
497
- }
498
- return true;
499
- }
500
- }