@firestitch/form 18.0.0 → 18.0.2
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/app/directives/validators/control.directive.d.ts +12 -9
- package/app/directives/validators/required.directive.d.ts +1 -1
- package/app/directives/validators/validate.directive.d.ts +2 -2
- package/app/validators/validators.d.ts +1 -1
- package/esm2022/app/components/form-template/form-template.component.mjs +1 -1
- package/esm2022/app/components/form-template/index.mjs +1 -1
- package/esm2022/app/components/form-template-outlet/form-template-outlet.component.mjs +1 -1
- package/esm2022/app/components/form-template-outlet/index.mjs +1 -1
- package/esm2022/app/directives/button.directive.mjs +2 -1
- package/esm2022/app/directives/form/form.directive.mjs +4 -4
- package/esm2022/app/directives/validators/control.directive.mjs +64 -63
- package/esm2022/app/directives/validators/function.directive.mjs +2 -2
- package/esm2022/app/directives/validators/required.directive.mjs +3 -3
- package/esm2022/app/directives/validators/validate.directive.mjs +6 -6
- package/esm2022/app/validators/validators.mjs +2 -2
- package/fesm2022/firestitch-form.mjs +74 -72
- package/fesm2022/firestitch-form.mjs.map +1 -1
- package/package.json +1 -1
- package/styles.scss +5 -19
|
@@ -253,9 +253,9 @@ class FsFormDirective {
|
|
|
253
253
|
_dialogRef;
|
|
254
254
|
_drawerRef;
|
|
255
255
|
_route;
|
|
256
|
-
wrapperSelector = '.fs-form-wrapper,.mat-form-field';
|
|
257
|
-
messageSelector = '.fs-form-message,.mat-form-field-subscript-wrapper';
|
|
258
|
-
hintSelector = '.fs-form-hint,.mat-form-field-hint-wrapper';
|
|
256
|
+
wrapperSelector = '.fs-form-wrapper,.mat-mdc-form-field';
|
|
257
|
+
messageSelector = '.fs-form-message,.mat-mdc-form-field-subscript-wrapper';
|
|
258
|
+
hintSelector = '.fs-form-hint,.mat-mdc-form-field-hint-wrapper';
|
|
259
259
|
labelSelector = '.fs-form-label,.mat-form-field-label';
|
|
260
260
|
autocomplete = false;
|
|
261
261
|
shortcuts = true; // Ctrl + s
|
|
@@ -1018,6 +1018,7 @@ class FsButtonDirective {
|
|
|
1018
1018
|
if (this._matButton && !this.active) {
|
|
1019
1019
|
this._previousDisabled = this._matButton.disabled;
|
|
1020
1020
|
this._matButton.disabled = true;
|
|
1021
|
+
this._matButton.disableRipple = true;
|
|
1021
1022
|
this._cdRef.markForCheck();
|
|
1022
1023
|
}
|
|
1023
1024
|
}
|
|
@@ -1321,11 +1322,11 @@ function messageProviderFactory() {
|
|
|
1321
1322
|
|
|
1322
1323
|
class FsControlDirective {
|
|
1323
1324
|
_elementRef;
|
|
1324
|
-
|
|
1325
|
-
|
|
1325
|
+
_renderer2;
|
|
1326
|
+
_injector;
|
|
1326
1327
|
_validateMessages;
|
|
1327
|
-
|
|
1328
|
-
|
|
1328
|
+
_ngControl;
|
|
1329
|
+
_formDirective;
|
|
1329
1330
|
wrapperSelector;
|
|
1330
1331
|
messageSelector;
|
|
1331
1332
|
hintSelector;
|
|
@@ -1343,15 +1344,15 @@ class FsControlDirective {
|
|
|
1343
1344
|
errors = [];
|
|
1344
1345
|
_control;
|
|
1345
1346
|
_destroy$ = new Subject();
|
|
1346
|
-
constructor(_elementRef,
|
|
1347
|
+
constructor(_elementRef, _renderer2, _injector, _validateMessages, _ngControl, _formDirective) {
|
|
1347
1348
|
this._elementRef = _elementRef;
|
|
1348
|
-
this.
|
|
1349
|
-
this.
|
|
1349
|
+
this._renderer2 = _renderer2;
|
|
1350
|
+
this._injector = _injector;
|
|
1350
1351
|
this._validateMessages = _validateMessages;
|
|
1351
|
-
this.
|
|
1352
|
-
this.
|
|
1353
|
-
if (
|
|
1354
|
-
this._control =
|
|
1352
|
+
this._ngControl = _ngControl;
|
|
1353
|
+
this._formDirective = _formDirective;
|
|
1354
|
+
if (_ngControl) {
|
|
1355
|
+
this._control = _ngControl.control;
|
|
1355
1356
|
}
|
|
1356
1357
|
else {
|
|
1357
1358
|
console.error('The element does not have a valid ngModel', this._elementRef.nativeElement);
|
|
@@ -1374,8 +1375,8 @@ class FsControlDirective {
|
|
|
1374
1375
|
if (this.messageSelector) {
|
|
1375
1376
|
return this.messageSelector;
|
|
1376
1377
|
}
|
|
1377
|
-
else if (this.
|
|
1378
|
-
return this.
|
|
1378
|
+
else if (this._formDirective?.messageSelector) {
|
|
1379
|
+
return this._formDirective.messageSelector;
|
|
1379
1380
|
}
|
|
1380
1381
|
}
|
|
1381
1382
|
getHintWrapperSelector() {
|
|
@@ -1385,8 +1386,8 @@ class FsControlDirective {
|
|
|
1385
1386
|
if (this.hintSelector) {
|
|
1386
1387
|
return this.hintSelector;
|
|
1387
1388
|
}
|
|
1388
|
-
else if (this.
|
|
1389
|
-
return this.
|
|
1389
|
+
else if (this._formDirective?.hintSelector) {
|
|
1390
|
+
return this._formDirective.hintSelector;
|
|
1390
1391
|
}
|
|
1391
1392
|
}
|
|
1392
1393
|
getWrapperSelector() {
|
|
@@ -1396,8 +1397,8 @@ class FsControlDirective {
|
|
|
1396
1397
|
if (this.wrapperSelector) {
|
|
1397
1398
|
return this.wrapperSelector;
|
|
1398
1399
|
}
|
|
1399
|
-
else if (this.
|
|
1400
|
-
return this.
|
|
1400
|
+
else if (this._formDirective?.wrapperSelector) {
|
|
1401
|
+
return this._formDirective.wrapperSelector;
|
|
1401
1402
|
}
|
|
1402
1403
|
}
|
|
1403
1404
|
getlabelSelector() {
|
|
@@ -1407,12 +1408,12 @@ class FsControlDirective {
|
|
|
1407
1408
|
if (this.labelSelector) {
|
|
1408
1409
|
return this.labelSelector;
|
|
1409
1410
|
}
|
|
1410
|
-
else if (this.
|
|
1411
|
-
return this.
|
|
1411
|
+
else if (this._formDirective?.labelSelector) {
|
|
1412
|
+
return this._formDirective.labelSelector;
|
|
1412
1413
|
}
|
|
1413
1414
|
}
|
|
1414
1415
|
getWrapperElement() {
|
|
1415
|
-
const wrapper = this.
|
|
1416
|
+
const wrapper = this._getWrapper(this._elementRef.nativeElement);
|
|
1416
1417
|
if (wrapper) {
|
|
1417
1418
|
return wrapper;
|
|
1418
1419
|
}
|
|
@@ -1427,14 +1428,16 @@ class FsControlDirective {
|
|
|
1427
1428
|
</div>
|
|
1428
1429
|
</mat-form-field>
|
|
1429
1430
|
*/
|
|
1431
|
+
get _shouldErrorBeRendered() {
|
|
1432
|
+
return this._ngControl.invalid
|
|
1433
|
+
&& (this._ngControl.dirty || this._formDirective?.ngForm?.submitted);
|
|
1434
|
+
}
|
|
1430
1435
|
render() {
|
|
1431
|
-
if (this.
|
|
1432
|
-
const renderer = this.
|
|
1436
|
+
if (this._ngControl) {
|
|
1437
|
+
const renderer = this._renderer2;
|
|
1433
1438
|
const wrapper = this.getWrapperElement();
|
|
1434
|
-
const error = this.
|
|
1435
|
-
|
|
1436
|
-
&& (this.ngControl.dirty || this.formDirective?.ngForm?.submitted);
|
|
1437
|
-
if (shouldErrorBeRendered && error) {
|
|
1439
|
+
const error = this._ngControl.dirty ? this._getError(this._ngControl) : null;
|
|
1440
|
+
if (this._shouldErrorBeRendered && error) {
|
|
1438
1441
|
wrapper.classList.add('ng-invalid', 'ng-dirty');
|
|
1439
1442
|
}
|
|
1440
1443
|
else {
|
|
@@ -1445,43 +1448,42 @@ class FsControlDirective {
|
|
|
1445
1448
|
}
|
|
1446
1449
|
const messageWrapper = wrapper.querySelector(this.getMessageSelector());
|
|
1447
1450
|
if (!messageWrapper) {
|
|
1448
|
-
return console
|
|
1449
|
-
|
|
1450
|
-
if (this.getlabelSelector()) {
|
|
1451
|
-
const labelWrapper = wrapper.querySelector(this.getlabelSelector());
|
|
1452
|
-
if (labelWrapper) {
|
|
1453
|
-
if (this.appendLabelClass) {
|
|
1454
|
-
this.renderer2.addClass(labelWrapper, this.appendLabelClass);
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1451
|
+
return console
|
|
1452
|
+
.warn(`Failed to locate ${this.getMessageSelector()}`, this._elementRef.nativeElement);
|
|
1457
1453
|
}
|
|
1458
1454
|
if (this.appendMessageClass) {
|
|
1459
1455
|
renderer.addClass(messageWrapper, this.appendMessageClass);
|
|
1460
1456
|
}
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1457
|
+
this._renderHint(error, messageWrapper);
|
|
1458
|
+
this._renderError(wrapper, messageWrapper, error);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
_renderHint(error, messageWrapper) {
|
|
1462
|
+
if (this.getHintWrapperSelector()) {
|
|
1463
|
+
const hints = messageWrapper.querySelectorAll('.mat-mdc-form-field-hint');
|
|
1464
|
+
hints.forEach((hint) => {
|
|
1465
|
+
this._renderer2.setStyle(hint, 'display', error ? 'none' : 'block');
|
|
1466
|
+
if (this.appendHintClass) {
|
|
1467
|
+
this._renderer2.addClass(hint, this.appendHintClass);
|
|
1468
1468
|
}
|
|
1469
|
-
}
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
renderer.addClass(errorWrapper, this.appendErrorClass);
|
|
1480
|
-
renderer.addClass(errorWrapper, `${this.appendErrorClass}-${error.name}`);
|
|
1481
|
-
const errorText = renderer.createText(error.message);
|
|
1482
|
-
renderer.appendChild(errorWrapper, errorText);
|
|
1483
|
-
messageWrapper.appendChild(errorWrapper);
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
_renderError(wrapper, messageWrapper, error) {
|
|
1473
|
+
let errorWrapper = wrapper.querySelector('.fs-form-error-target');
|
|
1474
|
+
if (errorWrapper) {
|
|
1475
|
+
errorWrapper.remove();
|
|
1476
|
+
}
|
|
1477
|
+
if (!this._shouldErrorBeRendered || !error) {
|
|
1478
|
+
return;
|
|
1484
1479
|
}
|
|
1480
|
+
errorWrapper = this._renderer2.createElement('div');
|
|
1481
|
+
this._renderer2.addClass(errorWrapper, 'fs-form-error-target');
|
|
1482
|
+
this._renderer2.addClass(errorWrapper, this.appendErrorClass);
|
|
1483
|
+
this._renderer2.addClass(errorWrapper, `${this.appendErrorClass}-${error.name}`);
|
|
1484
|
+
const errorText = this._renderer2.createText(error.message);
|
|
1485
|
+
this._renderer2.appendChild(errorWrapper, errorText);
|
|
1486
|
+
messageWrapper.querySelector(this.getHintWrapperSelector()).prepend(errorWrapper);
|
|
1485
1487
|
}
|
|
1486
1488
|
_subscribeToStatusChagnes() {
|
|
1487
1489
|
if (this._control) {
|
|
@@ -1490,30 +1492,30 @@ class FsControlDirective {
|
|
|
1490
1492
|
.subscribe(this.render.bind(this));
|
|
1491
1493
|
}
|
|
1492
1494
|
}
|
|
1493
|
-
|
|
1495
|
+
_getWrapper(node, count = 0) {
|
|
1494
1496
|
if (!node || count > 10) {
|
|
1495
1497
|
return null;
|
|
1496
1498
|
}
|
|
1497
1499
|
if (node.parentNode && node.parentNode.querySelector(this.getWrapperSelector())) {
|
|
1498
1500
|
return node;
|
|
1499
1501
|
}
|
|
1500
|
-
return this.
|
|
1502
|
+
return this._getWrapper(node.parentNode, ++count);
|
|
1501
1503
|
}
|
|
1502
|
-
|
|
1504
|
+
_parseErrorMessage(message, args) {
|
|
1503
1505
|
values(args)
|
|
1504
1506
|
.forEach((name) => {
|
|
1505
1507
|
message = message.replace(/\$\(\d\)/, name);
|
|
1506
1508
|
});
|
|
1507
1509
|
return message;
|
|
1508
1510
|
}
|
|
1509
|
-
|
|
1511
|
+
_getError(controlRef) {
|
|
1510
1512
|
const name = keys(controlRef.control.errors)[0];
|
|
1511
1513
|
if (!name) {
|
|
1512
1514
|
return null;
|
|
1513
1515
|
}
|
|
1514
1516
|
let message = controlRef.control.errors[name];
|
|
1515
1517
|
if (this._validateMessages[name]) {
|
|
1516
|
-
message = this.
|
|
1518
|
+
message = this._parseErrorMessage(this._validateMessages[name], message);
|
|
1517
1519
|
}
|
|
1518
1520
|
return { name: name, message: message };
|
|
1519
1521
|
}
|
|
@@ -1690,7 +1692,7 @@ class FsValidators {
|
|
|
1690
1692
|
}
|
|
1691
1693
|
catch (err) {
|
|
1692
1694
|
const error = err instanceof Error ? err.message : err;
|
|
1693
|
-
stream$ = throwError(error);
|
|
1695
|
+
stream$ = throwError(() => error);
|
|
1694
1696
|
}
|
|
1695
1697
|
if (!stream$) {
|
|
1696
1698
|
if (result instanceof Promise) {
|
|
@@ -1830,7 +1832,7 @@ class FsFormFunctionDirective extends FsControlDirective {
|
|
|
1830
1832
|
this._control.updateValueAndValidity();
|
|
1831
1833
|
}
|
|
1832
1834
|
validateAsync(control) {
|
|
1833
|
-
if (this.validateOnSubmit && !this.
|
|
1835
|
+
if (this.validateOnSubmit && !this._formDirective.validating) {
|
|
1834
1836
|
return of(null);
|
|
1835
1837
|
}
|
|
1836
1838
|
return FsValidators.func(this._control, this.fsFormFunction, this.fsFormFunctionData);
|
|
@@ -2337,10 +2339,10 @@ class FsFormRequiredDirective extends FsControlDirective {
|
|
|
2337
2339
|
// Adding class fs-form-label-requried adds the * to the label
|
|
2338
2340
|
if (labelWrapper) {
|
|
2339
2341
|
if (this.required) {
|
|
2340
|
-
this.
|
|
2342
|
+
this._renderer2.addClass(labelWrapper, 'fs-form-label-required');
|
|
2341
2343
|
}
|
|
2342
2344
|
else {
|
|
2343
|
-
this.
|
|
2345
|
+
this._renderer2.removeClass(labelWrapper, 'fs-form-label-required');
|
|
2344
2346
|
}
|
|
2345
2347
|
}
|
|
2346
2348
|
}
|
|
@@ -2415,14 +2417,14 @@ class FsFormValidateDirective extends FsControlDirective {
|
|
|
2415
2417
|
this._control.updateValueAndValidity();
|
|
2416
2418
|
}
|
|
2417
2419
|
validateAsync(control) {
|
|
2418
|
-
if (this.validateOnSubmit && !this.
|
|
2420
|
+
if (this.validateOnSubmit && !this._formDirective.validating) {
|
|
2419
2421
|
return of(null);
|
|
2420
2422
|
}
|
|
2421
2423
|
return FsValidators.func(this._control, this.validateFn, this.validateFnData);
|
|
2422
2424
|
}
|
|
2423
2425
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: FsFormValidateDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive });
|
|
2424
2426
|
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.7", type: FsFormValidateDirective, selector: "[validate]", inputs: { validateFn: ["validate", "validateFn"], validateFnData: ["validateData", "validateFnData"], validateOnSubmit: "validateOnSubmit" }, providers: [
|
|
2425
|
-
VALIDATE_MESSAGE_PROVIDER
|
|
2427
|
+
VALIDATE_MESSAGE_PROVIDER,
|
|
2426
2428
|
], usesInheritance: true, usesOnChanges: true, ngImport: i0 });
|
|
2427
2429
|
}
|
|
2428
2430
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: FsFormValidateDirective, decorators: [{
|
|
@@ -2430,7 +2432,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.7", ngImpor
|
|
|
2430
2432
|
args: [{
|
|
2431
2433
|
selector: '[validate]',
|
|
2432
2434
|
providers: [
|
|
2433
|
-
VALIDATE_MESSAGE_PROVIDER
|
|
2435
|
+
VALIDATE_MESSAGE_PROVIDER,
|
|
2434
2436
|
],
|
|
2435
2437
|
}]
|
|
2436
2438
|
}], propDecorators: { validateFn: [{
|