@klippa/ngx-enhancy-forms 5.0.0 → 5.1.0
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/bundles/klippa-ngx-enhancy-forms.umd.js +37 -6
- package/bundles/klippa-ngx-enhancy-forms.umd.js.map +1 -1
- package/bundles/klippa-ngx-enhancy-forms.umd.min.js +2 -2
- package/bundles/klippa-ngx-enhancy-forms.umd.min.js.map +1 -1
- package/esm2015/lib/elements/value-accessor-base/value-accessor-base.component.js +24 -6
- package/esm2015/lib/form/form-element/form-element.component.js +14 -4
- package/esm2015/lib/util/values.js +4 -1
- package/fesm2015/klippa-ngx-enhancy-forms.js +37 -7
- package/fesm2015/klippa-ngx-enhancy-forms.js.map +1 -1
- package/klippa-ngx-enhancy-forms.metadata.json +1 -1
- package/lib/elements/value-accessor-base/value-accessor-base.component.d.ts +4 -1
- package/lib/form/form-element/form-element.component.d.ts +5 -1
- package/lib/util/values.d.ts +1 -0
- package/package.json +1 -1
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
}
|
|
32
32
|
return s.substring(0, length) + '...';
|
|
33
33
|
}
|
|
34
|
+
function arrayIsSetAndFilled(arr) {
|
|
35
|
+
return arr !== null && arr !== undefined && arr.length > 0;
|
|
36
|
+
}
|
|
34
37
|
|
|
35
38
|
var invalidFieldsSymbol = Symbol('Not all fields are valid');
|
|
36
39
|
var SubFormDirective = /** @class */ (function () {
|
|
@@ -225,6 +228,7 @@
|
|
|
225
228
|
this.customMessages = customMessages;
|
|
226
229
|
this.direction = 'horizontal';
|
|
227
230
|
this.captionSpacing = 'percentages';
|
|
231
|
+
this.spaceDistribution = '40-60';
|
|
228
232
|
this.swapInputAndCaption = false;
|
|
229
233
|
this.errorMessages = DEFAULT_ERROR_MESSAGES;
|
|
230
234
|
this.customErrorHandlers = [];
|
|
@@ -234,9 +238,11 @@
|
|
|
234
238
|
return msg.replace("%" + key + "%", parameters[key]);
|
|
235
239
|
}, message);
|
|
236
240
|
};
|
|
237
|
-
FormElementComponent.prototype.registerControl = function (formControl) {
|
|
241
|
+
FormElementComponent.prototype.registerControl = function (formControl, input) {
|
|
242
|
+
if (input === void 0) { input = null; }
|
|
238
243
|
this.attachedControl = formControl;
|
|
239
244
|
this.parent.registerControl(formControl, this);
|
|
245
|
+
this.input = input;
|
|
240
246
|
};
|
|
241
247
|
FormElementComponent.prototype.unregisterControl = function (formControl) {
|
|
242
248
|
this.attachedControl = null;
|
|
@@ -281,6 +287,12 @@
|
|
|
281
287
|
// to give some breathing room, we scroll 100px more to the top
|
|
282
288
|
(_a = this.getScrollableParent(this.internalComponentRef.nativeElement)) === null || _a === void 0 ? void 0 : _a.scrollBy(0, -100);
|
|
283
289
|
};
|
|
290
|
+
FormElementComponent.prototype.isRequired = function () {
|
|
291
|
+
if (isValueSet(this.input)) {
|
|
292
|
+
return this.input.hasValidator('required');
|
|
293
|
+
}
|
|
294
|
+
return false;
|
|
295
|
+
};
|
|
284
296
|
FormElementComponent.prototype.getErrorMessage = function (key) {
|
|
285
297
|
var _a, _b, _c;
|
|
286
298
|
return (_c = (_b = (_a = this.customMessages) === null || _a === void 0 ? void 0 : _a[key]) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : this.errorMessages[key];
|
|
@@ -290,8 +302,8 @@
|
|
|
290
302
|
FormElementComponent.decorators = [
|
|
291
303
|
{ type: core.Component, args: [{
|
|
292
304
|
selector: 'klp-form-element',
|
|
293
|
-
template: "<ng-template #errorRef>\n\t<div *ngIf=\"getErrorToShow()\" class=\"errorContainer\">\n\t\t<div *ngIf=\"showDefaultError('min')\">{{substituteParameters(getErrorMessage(\"min\"), {min: attachedControl.errors.min.min})}}</div>\n\t\t<div *ngIf=\"showDefaultError('max')\">{{substituteParameters(getErrorMessage(\"max\"), {max: attachedControl.errors.max.max})}}</div>\n\t\t<div *ngIf=\"showDefaultError('required')\">{{getErrorMessage(\"required\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('email')\">{{getErrorMessage(\"email\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('minlength')\">{{substituteParameters(getErrorMessage(\"minLength\"), {minLength: attachedControl.errors.minlength.requiredLength})}}</div>\n\t\t<div *ngIf=\"showDefaultError('maxlength')\">{{substituteParameters(getErrorMessage(\"maxLength\"), {maxLength: attachedControl.errors.maxlength.requiredLength})}}</div>\n\t\t<div *ngIf=\"showDefaultError('pattern')\">{{getErrorMessage(\"pattern\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('MatchPassword')\">{{getErrorMessage(\"matchPassword\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('date')\">{{getErrorMessage(\"date\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('message')\">{{attachedControl.errors.message.value}}</div>\n\t\t<div [ngTemplateOutlet]=\"getCustomErrorHandler(getErrorToShow())?.templateRef\"></div>\n\t</div>\n</ng-template>\n<ng-container *ngIf=\"direction === 'horizontal'\" [ngTemplateOutlet]=\"errorRef\"></ng-container>\n<div *ngIf=\"attachedControl\" class=\"componentContainer\" [ngClass]=\"{vertical: direction === 'vertical', reverseOrder: swapInputAndCaption}\" #internalComponentRef>\n\t<div class=\"caption\" [ngClass]=\"{ hasErrors: getErrorToShow() && attachedControl.touched, percentageSpacing: captionSpacing === 'percentages' }\">\n\t\t<div *ngIf=\"captionRef\" [ngTemplateOutlet]=\"captionRef\"></div>\n\t\t<div *ngIf=\"!captionRef\">{{caption}}
|
|
294
|
-
styles: [":host{display:block
|
|
305
|
+
template: "<ng-template #errorRef>\n\t<div *ngIf=\"getErrorToShow()\" class=\"errorContainer\">\n\t\t<div *ngIf=\"showDefaultError('min')\">{{substituteParameters(getErrorMessage(\"min\"), {min: attachedControl.errors.min.min})}}</div>\n\t\t<div *ngIf=\"showDefaultError('max')\">{{substituteParameters(getErrorMessage(\"max\"), {max: attachedControl.errors.max.max})}}</div>\n\t\t<div *ngIf=\"showDefaultError('required')\">{{getErrorMessage(\"required\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('email')\">{{getErrorMessage(\"email\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('minlength')\">{{substituteParameters(getErrorMessage(\"minLength\"), {minLength: attachedControl.errors.minlength.requiredLength})}}</div>\n\t\t<div *ngIf=\"showDefaultError('maxlength')\">{{substituteParameters(getErrorMessage(\"maxLength\"), {maxLength: attachedControl.errors.maxlength.requiredLength})}}</div>\n\t\t<div *ngIf=\"showDefaultError('pattern')\">{{getErrorMessage(\"pattern\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('MatchPassword')\">{{getErrorMessage(\"matchPassword\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('date')\">{{getErrorMessage(\"date\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('message')\">{{attachedControl.errors.message.value}}</div>\n\t\t<div [ngTemplateOutlet]=\"getCustomErrorHandler(getErrorToShow())?.templateRef\"></div>\n\t</div>\n</ng-template>\n<ng-container *ngIf=\"direction === 'horizontal'\" [ngTemplateOutlet]=\"errorRef\"></ng-container>\n<div *ngIf=\"attachedControl\" class=\"componentContainer\" [ngClass]=\"{vertical: direction === 'vertical', reverseOrder: swapInputAndCaption}\" #internalComponentRef>\n\t<div class=\"caption\" *ngIf=\"caption || captionRef\" [ngClass]=\"{ hasErrors: getErrorToShow() && attachedControl.touched, percentageSpacing: captionSpacing === 'percentages', 'd30-70': spaceDistribution === '30-70' }\">\n\t\t<div *ngIf=\"captionRef\" class=\"captionRefContainer\">\n\t\t\t<ng-container [ngTemplateOutlet]=\"captionRef\"></ng-container>\n\t\t\t<div *ngIf=\"isRequired()\"> *</div>\n\t\t</div>\n\t\t<div *ngIf=\"!captionRef\">{{caption}}<span *ngIf=\"isRequired()\"> *</span></div>\n\t</div>\n\t<ng-container *ngIf=\"direction === 'vertical'\" [ngTemplateOutlet]=\"errorRef\"></ng-container>\n\t<div class=\"inputContainer\" [ngClass]=\"{ percentageSpacing: captionSpacing === 'percentages', 'd30-70': spaceDistribution === '30-70' }\">\n\t\t<ng-content></ng-content>\n\t</div>\n</div>\n",
|
|
306
|
+
styles: [":host{display:block}.componentContainer{align-items:center;display:flex}.componentContainer.reverseOrder{flex-direction:row-reverse;justify-content:flex-end}.componentContainer.vertical{display:block;margin-bottom:1rem}.componentContainer.vertical .inputContainer{margin-top:.3125rem}.componentContainer.vertical .errorContainer{margin-left:0}.captionRefContainer{display:flex}.caption{color:#515365;flex:0 0 auto;font-weight:700}.caption.percentageSpacing{flex:0 0 40%}.caption.percentageSpacing.d30-70{flex-basis:30%}.caption.hasErrors{color:#ff8000}.inputContainer{flex:1}.inputContainer.percentageSpacing{flex:0 0 60%}.inputContainer.percentageSpacing.d30-70{flex-basis:70%}.errorContainer{color:#ff8000;margin-left:40%}.errorContainer.d30-70{margin-left:30%}"]
|
|
295
307
|
},] }
|
|
296
308
|
];
|
|
297
309
|
FormElementComponent.ctorParameters = function () { return [
|
|
@@ -302,6 +314,7 @@
|
|
|
302
314
|
caption: [{ type: core.Input }],
|
|
303
315
|
direction: [{ type: core.Input }],
|
|
304
316
|
captionSpacing: [{ type: core.Input }],
|
|
317
|
+
spaceDistribution: [{ type: core.Input }],
|
|
305
318
|
swapInputAndCaption: [{ type: core.Input }],
|
|
306
319
|
internalComponentRef: [{ type: core.ViewChild, args: ['internalComponentRef',] }]
|
|
307
320
|
};
|
|
@@ -325,10 +338,12 @@
|
|
|
325
338
|
// we support both providing just the formControlName and the full formControl
|
|
326
339
|
this.formControlName = null;
|
|
327
340
|
this.formControl = null;
|
|
341
|
+
this.onTouch = new core.EventEmitter();
|
|
342
|
+
this.validators = [];
|
|
328
343
|
}
|
|
329
344
|
ValueAccessorBase.prototype.ngOnInit = function () {
|
|
330
345
|
var _this = this;
|
|
331
|
-
var _a, _b, _c;
|
|
346
|
+
var _a, _b, _c, _d;
|
|
332
347
|
if (this.formControl) {
|
|
333
348
|
this.attachedFormControl = this.formControl;
|
|
334
349
|
}
|
|
@@ -343,7 +358,16 @@
|
|
|
343
358
|
this.attachedFormControl.statusChanges.subscribe(function () {
|
|
344
359
|
_this.disabled = _this.attachedFormControl.disabled;
|
|
345
360
|
});
|
|
346
|
-
(_c = this.parent) === null || _c === void 0 ? void 0 : _c.registerControl(this.attachedFormControl);
|
|
361
|
+
(_c = this.parent) === null || _c === void 0 ? void 0 : _c.registerControl(this.attachedFormControl, this);
|
|
362
|
+
if ((_d = this.attachedFormControl) === null || _d === void 0 ? void 0 : _d.validator) {
|
|
363
|
+
var vals = this.attachedFormControl.validator({});
|
|
364
|
+
if (isValueSet(vals)) {
|
|
365
|
+
this.validators = Object.keys(vals);
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
this.validators = [];
|
|
369
|
+
}
|
|
370
|
+
}
|
|
347
371
|
}
|
|
348
372
|
};
|
|
349
373
|
ValueAccessorBase.prototype.isInErrorState = function () {
|
|
@@ -374,6 +398,12 @@
|
|
|
374
398
|
ValueAccessorBase.prototype.resetToNull = function () {
|
|
375
399
|
this.setInnerValueAndNotify(null);
|
|
376
400
|
};
|
|
401
|
+
ValueAccessorBase.prototype.hasValidator = function (validatorName) {
|
|
402
|
+
if (arrayIsSetAndFilled(this.validators)) {
|
|
403
|
+
return this.validators.includes(validatorName);
|
|
404
|
+
}
|
|
405
|
+
return false;
|
|
406
|
+
};
|
|
377
407
|
return ValueAccessorBase;
|
|
378
408
|
}());
|
|
379
409
|
ValueAccessorBase.decorators = [
|
|
@@ -389,7 +419,8 @@
|
|
|
389
419
|
ValueAccessorBase.propDecorators = {
|
|
390
420
|
disabled: [{ type: core.Input }],
|
|
391
421
|
formControlName: [{ type: core.Input }],
|
|
392
|
-
formControl: [{ type: core.Input }]
|
|
422
|
+
formControl: [{ type: core.Input }],
|
|
423
|
+
onTouch: [{ type: core.Output }]
|
|
393
424
|
};
|
|
394
425
|
|
|
395
426
|
var ButtonComponent = /** @class */ (function () {
|