UNPKG

ion-form-error-messages

Version:

An ionic 4 component that will display a list of error messages for a given reactive form formGroup object.

16 lines (14 loc) 4.43 kB
!function(r,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@angular/core"),require("@angular/forms"),require("@angular/common"),require("@ionic/angular")):"function"==typeof define&&define.amd?define("ion-form-error-messages",["exports","@angular/core","@angular/forms","@angular/common","@ionic/angular"],o):o((r=r||self)["ion-form-error-messages"]={},r.ng.core,r.ng.forms,r.ng.common,r.angular)}(this,(function(r,o,n,e,t){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */function i(r){var o="function"==typeof Symbol&&r[Symbol.iterator],n=0;return o?o.call(r):{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}}}var s=function(){function r(){this.color="danger"}return Object.defineProperty(r.prototype,"filteredControls",{get:function(){if(!this.formGroup)return[];var r=this.objectToKeys(this.formGroup.controls);if(r&&(this.controls||this.control)){var o=[];this.control&&o.push(this.control),Array.isArray(this.controls)&&(o=o.concat(this.controls)),o.length&&(r=r.filter((function(r){return o.indexOf(r)>=0})))}return r},enumerable:!0,configurable:!0}),r.prototype.ngOnInit=function(){},r.prototype.getErrors=function(r){return this.formGroup&&this.formGroup.controls&&this.formGroup.controls[r]?this.formGroup.controls[r].errors:{}},r.prototype.isAnyControlInvalid=function(){var r,o,n=Object.keys(this.formGroup.controls),e=!1;try{for(var t=i(n),s=t.next();!s.done;s=t.next()){var a=s.value;if(this.isControlInvalid(a)){e=!0;break}}}catch(o){r={error:o}}finally{try{s&&!s.done&&(o=t.return)&&o.call(t)}finally{if(r)throw r.error}}return e},r.prototype.isControlInvalid=function(r){var o,n,e=this.formGroup.controls[r];if(e&&e.errors){var t=Object.keys(e.errors),s=!1;try{for(var a=i(t),l=a.next();!l.done;l=a.next()){var c=l.value;if(this.messages[r][c]){s=!0;break}}}catch(r){o={error:r}}finally{try{l&&!l.done&&(n=a.return)&&n.call(a)}finally{if(o)throw o.error}}return e.invalid&&s&&(e.dirty||e.touched)}return!1},r.prototype.objectToKeys=function(r){return r?Object.keys(r):r},r.decorators=[{type:o.Component,args:[{selector:"ion-form-error-messages",template:'\n <ion-item *ngIf="isAnyControlInvalid()" lines="none">\n <ion-grid class="ion-no-padding">\n <ng-container *ngFor="let controlKey of filteredControls">\n <ng-container *ngFor="let errorKey of objectToKeys(getErrors(controlKey))">\n <ng-container *ngIf="messages[controlKey] || {} as errorMessages">\n <ion-row *ngIf="errorMessages[errorKey]">\n <ion-col class="ion-no-padding ion-text-wrap">\n <ion-text [color]="color" [innerHtml]="errorMessages[errorKey]"> </ion-text>\n </ion-col>\n </ion-row>\n </ng-container>\n </ng-container>\n </ng-container>\n </ion-grid>\n </ion-item>\n ',styles:[" ion-item { --min-height: 16px; font-size: 14px;}"]}]}],r.ctorParameters=function(){return[]},r.propDecorators={formGroup:[{type:o.Input}],messages:[{type:o.Input}],color:[{type:o.Input}],control:[{type:o.Input}],controls:[{type:o.Input}]},r}();var a=function(){function r(){}return r.decorators=[{type:o.NgModule,args:[{declarations:[s],imports:[e.CommonModule,n.FormsModule,t.IonicModule],exports:[s]}]}],r}();r.IonFormErrorMessagesComponent=s,r.IonFormErrorMessagesModule=a,Object.defineProperty(r,"__esModule",{value:!0})})); //# sourceMappingURL=ion-form-error-messages.umd.min.js.map