@acorex/components 7.17.22 → 7.17.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.
- package/check-box/lib/check-box.component.d.ts +3 -3
- package/collapse/lib/collapse.component.d.ts +7 -1
- package/common/lib/classes/components.class.d.ts +11 -0
- package/common/lib/components/value-component.class.d.ts +10 -4
- package/drawer/lib/drawer.component.d.ts +4 -1
- package/esm2022/calendar/lib/calendar-range.component.mjs +1 -2
- package/esm2022/calendar/lib/calendar.component.mjs +10 -2
- package/esm2022/check-box/lib/check-box.component.mjs +9 -4
- package/esm2022/collapse/lib/collapse.component.mjs +21 -3
- package/esm2022/color-palette/lib/color-palette.component.mjs +4 -2
- package/esm2022/common/lib/classes/components.class.mjs +1 -1
- package/esm2022/common/lib/components/value-component.class.mjs +38 -65
- package/esm2022/data-pager/lib/data-pager.component.mjs +1 -2
- package/esm2022/data-table/lib/data-table.component.mjs +2 -2
- package/esm2022/drawer/lib/drawer.component.mjs +18 -8
- package/esm2022/form/index.mjs +2 -3
- package/esm2022/form/lib/form-field.component.mjs +34 -6
- package/esm2022/form/lib/form.component.mjs +44 -86
- package/esm2022/form/lib/form.config.mjs +3 -23
- package/esm2022/form/lib/form.module.mjs +9 -8
- package/esm2022/form/lib/validation-rule.directive.mjs +33 -0
- package/esm2022/form/lib/validation-summary.component.mjs +19 -13
- package/esm2022/label/lib/label.component.mjs +21 -10
- package/esm2022/number-box/lib/number-box.component.mjs +8 -3
- package/esm2022/otp/lib/otp.component.mjs +1 -1
- package/esm2022/password-box/lib/password-box.component.mjs +4 -2
- package/esm2022/radio/lib/radio.component.mjs +2 -2
- package/esm2022/select-box/lib/select-box.component.mjs +1 -2
- package/esm2022/selection-list/lib/selection-list.component.mjs +8 -8
- package/fesm2022/acorex-components-calendar.mjs +9 -2
- package/fesm2022/acorex-components-calendar.mjs.map +1 -1
- package/fesm2022/acorex-components-check-box.mjs +8 -3
- package/fesm2022/acorex-components-check-box.mjs.map +1 -1
- package/fesm2022/acorex-components-collapse.mjs +20 -2
- package/fesm2022/acorex-components-collapse.mjs.map +1 -1
- package/fesm2022/acorex-components-color-palette.mjs +3 -1
- package/fesm2022/acorex-components-color-palette.mjs.map +1 -1
- package/fesm2022/acorex-components-common.mjs +36 -63
- package/fesm2022/acorex-components-common.mjs.map +1 -1
- package/fesm2022/acorex-components-data-pager.mjs +0 -1
- package/fesm2022/acorex-components-data-pager.mjs.map +1 -1
- package/fesm2022/acorex-components-data-table.mjs +2 -2
- package/fesm2022/acorex-components-data-table.mjs.map +1 -1
- package/fesm2022/acorex-components-drawer.mjs +17 -7
- package/fesm2022/acorex-components-drawer.mjs.map +1 -1
- package/fesm2022/acorex-components-form.mjs +135 -250
- package/fesm2022/acorex-components-form.mjs.map +1 -1
- package/fesm2022/acorex-components-label.mjs +19 -8
- package/fesm2022/acorex-components-label.mjs.map +1 -1
- package/fesm2022/acorex-components-number-box.mjs +7 -2
- package/fesm2022/acorex-components-number-box.mjs.map +1 -1
- package/fesm2022/acorex-components-otp.mjs.map +1 -1
- package/fesm2022/acorex-components-password-box.mjs +3 -1
- package/fesm2022/acorex-components-password-box.mjs.map +1 -1
- package/fesm2022/acorex-components-radio.mjs +1 -1
- package/fesm2022/acorex-components-radio.mjs.map +1 -1
- package/fesm2022/acorex-components-select-box.mjs +0 -1
- package/fesm2022/acorex-components-select-box.mjs.map +1 -1
- package/fesm2022/acorex-components-selection-list.mjs +6 -6
- package/fesm2022/acorex-components-selection-list.mjs.map +1 -1
- package/form/index.d.ts +1 -2
- package/form/lib/form-field.component.d.ts +8 -2
- package/form/lib/form.component.d.ts +9 -13
- package/form/lib/form.config.d.ts +0 -10
- package/form/lib/form.module.d.ts +3 -2
- package/form/lib/validation-rule.directive.d.ts +16 -0
- package/form/lib/validation-summary.component.d.ts +8 -5
- package/label/lib/label.component.d.ts +6 -6
- package/package.json +7 -7
- package/selection-list/lib/selection-list.component.d.ts +2 -2
- package/esm2022/form/lib/validation-rule.widget.mjs +0 -124
- package/esm2022/form/lib/validation.class.mjs +0 -2
- package/form/lib/validation-rule.widget.d.ts +0 -23
- package/form/lib/validation.class.d.ts +0 -18
@@ -10,6 +10,7 @@ import { map, pairwise, filter as filter$1, startWith, exhaustMap } from 'rxjs/o
|
|
10
10
|
import { classes } from 'polytype';
|
11
11
|
import { AXHtmlUtil } from '@acorex/core/utils';
|
12
12
|
import { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion';
|
13
|
+
import { AXValidationService } from '@acorex/core/validation';
|
13
14
|
import { AXTranslator } from '@acorex/core/translation';
|
14
15
|
import * as i1$1 from '@angular/forms';
|
15
16
|
|
@@ -1120,6 +1121,9 @@ class MXValueComponent extends MXInteractiveComponent {
|
|
1120
1121
|
this._isUserInteraction = false;
|
1121
1122
|
this.stateChange = new EventEmitter();
|
1122
1123
|
this._state = 'clear';
|
1124
|
+
this.validationService = inject(AXValidationService);
|
1125
|
+
this.validationRulesChange = new EventEmitter();
|
1126
|
+
this.validationRules = [];
|
1123
1127
|
this.onChangeCallback = noop;
|
1124
1128
|
}
|
1125
1129
|
/**
|
@@ -1162,11 +1166,11 @@ class MXValueComponent extends MXInteractiveComponent {
|
|
1162
1166
|
if (!isEqual(old, v)) {
|
1163
1167
|
this._value = v;
|
1164
1168
|
this.emitOnValueChangedEvent(old, this.value);
|
1165
|
-
if (v == null || v == undefined || v == '' || (Array.isArray(v) && v.length == 0)) {
|
1166
|
-
this.setState('clear');
|
1167
|
-
}
|
1168
1169
|
this.internalValueChanged(this.value);
|
1169
1170
|
}
|
1171
|
+
if (v == null || v == undefined || v == '' || (Array.isArray(v) && v.length == 0)) {
|
1172
|
+
this.setState('clear');
|
1173
|
+
}
|
1170
1174
|
}
|
1171
1175
|
get state() {
|
1172
1176
|
return this._state;
|
@@ -1195,77 +1199,46 @@ class MXValueComponent extends MXInteractiveComponent {
|
|
1195
1199
|
return value;
|
1196
1200
|
}
|
1197
1201
|
internalValueChanged(value) { }
|
1198
|
-
ngAfterViewInit() {
|
1199
|
-
const a = this.getHostElement().querySelectorAll('[ax-form-input="true"]');
|
1200
|
-
a.forEach((c) => {
|
1201
|
-
c.removeAttribute('ax-form-input');
|
1202
|
-
});
|
1203
|
-
this.getHostElement().setAttribute('ax-form-input', 'true');
|
1204
|
-
this._checkRequired();
|
1205
|
-
}
|
1206
1202
|
ngOnDestroy() {
|
1207
1203
|
this.onValueChanged?.unsubscribe();
|
1208
1204
|
this.onOptionChanged?.unsubscribe();
|
1209
1205
|
}
|
1210
|
-
|
1211
|
-
|
1212
|
-
//
|
1213
|
-
if (isRequired) {
|
1214
|
-
const container = this.getHostElement().classList.contains('ax-editor-container')
|
1215
|
-
? this.getHostElement()
|
1216
|
-
: this.getHostElement().querySelector('.ax-editor-container');
|
1217
|
-
const formField = container?.closest('ax-form-field');
|
1218
|
-
const label = formField?.querySelector('ax-label')?.__axContext__;
|
1219
|
-
if (label)
|
1220
|
-
label.required = true;
|
1221
|
-
}
|
1206
|
+
get isRequired() {
|
1207
|
+
return this.validationRules?.some(c => c.rule == 'required');
|
1222
1208
|
}
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1209
|
+
addValidationRule(rule) {
|
1210
|
+
this.validationRules.push(rule);
|
1211
|
+
this.validationRulesChange.emit(this.validationRules);
|
1212
|
+
}
|
1213
|
+
removeValidationRule(rule) {
|
1214
|
+
this.validationRules = this.validationRules.filter(r => r.rule !== rule.rule || !isEqual(r.options, rule.options));
|
1215
|
+
this.validationRulesChange.emit(this.validationRules);
|
1216
|
+
}
|
1217
|
+
async validate() {
|
1218
|
+
const rules = this.validationService.ruleFor(this.value);
|
1219
|
+
this.validationRules.forEach(r => {
|
1220
|
+
rules.addRule(r.rule, r.options);
|
1221
|
+
});
|
1222
|
+
const result = await rules.validate();
|
1223
|
+
if (result.result) {
|
1227
1224
|
this.setState('clear');
|
1228
|
-
return Promise.resolve({
|
1229
|
-
result: true,
|
1230
|
-
value: this.value,
|
1231
|
-
name: this.name,
|
1232
|
-
id: this.id,
|
1233
|
-
});
|
1234
1225
|
}
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
if (error) {
|
1243
|
-
this.setState('error', error.message);
|
1244
|
-
resolve({
|
1245
|
-
result: false,
|
1246
|
-
value: this.value,
|
1247
|
-
message: error.message,
|
1248
|
-
name: this.name,
|
1249
|
-
id: this.id,
|
1250
|
-
});
|
1251
|
-
}
|
1252
|
-
else {
|
1253
|
-
this.setState('success');
|
1254
|
-
resolve({
|
1255
|
-
result: true,
|
1256
|
-
value: this.value,
|
1257
|
-
name: this.name,
|
1258
|
-
id: this.id,
|
1259
|
-
});
|
1260
|
-
}
|
1261
|
-
});
|
1226
|
+
else {
|
1227
|
+
const message = result.rules.find(c => !c.result).message;
|
1228
|
+
this.setState('error', message);
|
1229
|
+
}
|
1230
|
+
result.rules.forEach(r => {
|
1231
|
+
// set name & title for validation summary component
|
1232
|
+
r["name"] = this.name;
|
1262
1233
|
});
|
1234
|
+
return result;
|
1263
1235
|
}
|
1264
1236
|
setState(state, ...args) {
|
1237
|
+
//TODO: find a better solution
|
1265
1238
|
const container = this.getHostElement().classList.contains('ax-editor-container')
|
1266
1239
|
? this.getHostElement()
|
1267
1240
|
: this.getHostElement().querySelector('.ax-editor-container');
|
1268
|
-
const formField = container?.closest('
|
1241
|
+
const formField = container?.closest('ax-form-field');
|
1269
1242
|
const label = formField?.querySelector('ax-label') || formField?.querySelector('label');
|
1270
1243
|
let target = container || this.getHostElement().firstElementChild;
|
1271
1244
|
if (target?.querySelector('.ax-error-container')) {
|
@@ -1292,7 +1265,7 @@ class MXValueComponent extends MXInteractiveComponent {
|
|
1292
1265
|
this.setState('clear');
|
1293
1266
|
if (args[0]) {
|
1294
1267
|
const span = document.createElement('span');
|
1295
|
-
span.
|
1268
|
+
span.innerHTML = args[0];
|
1296
1269
|
span.classList.add('ax-error-message');
|
1297
1270
|
parent.appendChild(span);
|
1298
1271
|
}
|
@@ -1317,7 +1290,7 @@ class MXValueComponent extends MXInteractiveComponent {
|
|
1317
1290
|
}
|
1318
1291
|
this.writeValue(value);
|
1319
1292
|
}
|
1320
|
-
clear(e) {
|
1293
|
+
clear(e = false) {
|
1321
1294
|
this.commitValue(null, e);
|
1322
1295
|
}
|
1323
1296
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: MXValueComponent, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
|