ngx-number-input
Version:
Componente angular para formatear números dentro de un input
2 lines • 3.91 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/forms"),require("@angular/common")):"function"==typeof define&&define.amd?define("ngx-number-input",["exports","@angular/core","@angular/forms","@angular/common"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["ngx-number-input"]={},e.ng.core,e.ng.forms,e.ng.common)}(this,(function(e,t,n,r){"use strict";var i=function(){function e(){this.placeholder="",this.locale="en-GB",this.currency=null,this.onChange=function(e){},this.onTouched=function(){},this.isFocused=!1}return Object.defineProperty(e.prototype,"max",{get:function(){return this._max},set:function(e){this._max=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"min",{get:function(){return this._min},set:function(e){this._min=e},enumerable:!1,configurable:!0}),e.prototype.ngOnInit=function(){},e.prototype.ngOnChanges=function(e){e.max&&(this.max=e.max.currentValue),e.min&&(this.min=e.min.currentValue)},e.prototype.validate=function(e){var t=e.value,n=!1;return!this.isRequired||this.value&&""!=this.value.toString()?(this.value&&(!(n=this.value!==Number(t))&&this.min&&(n=Number(t)<this.min),!n&&this.max&&(n=Number(t)>this.max)),n?{invalid:!0,max:this.max?Number(t)>this.max:null,min:this.min?Number(t)<this.min:null}:null):{invalid:!0,required:!0}},e.prototype.updateChanges=function(){this.onChange(this.value)},e.prototype.writeValue=function(e){this.value=e,this.updateChanges()},e.prototype.registerOnChange=function(e){this.onChange=e},e.prototype.registerOnTouched=function(e){this.onTouched=e},Object.defineProperty(e.prototype,"numberFormatted",{get:function(){if(!this.value)return"";if(!this.currency)return Number(this.value).toLocaleString(this.locale,{});try{return Number(this.value).toLocaleString(this.locale,{style:"currency",currency:this.currency})}catch(e){return Number(this.value).toLocaleString(this.locale)}},enumerable:!1,configurable:!0}),e.prototype.onFocus=function(){var e=this;this.isFocused=!0,setTimeout((function(){e.inputN.nativeElement.focus()}),0)},e.prototype.onBlur=function(){this.onTouched(),this.isFocused=!1},e}();i.decorators=[{type:t.Component,args:[{selector:"ngx-number-input",template:'<input type="number" [(ngModel)]="value" [attr.max]="max" [attr.min]="min" [attr.class]="klass" [ngClass]="ngClass" (change)="updateChanges()" [placeholder]="placeholder" (blur)="onBlur()" [required]="isRequired" [disabled]="isDisabled" [readonly]="isReadOnly"\n *ngIf="isFocused" #inputN>\n<input type="text" value="{{ numberFormatted }}" [attr.max]="max" [attr.min]="min" [ngClass]="ngClass" [required]="isRequired" [attr.class]="klass" [disabled]="isDisabled" [readonly]="isReadOnly" [placeholder]="placeholder" (focus)="onFocus()" *ngIf="!isFocused">\n<p *ngIf="isFocused"><span class="text-muted">{{ numberFormatted }}</span></p>',providers:[{provide:n.NG_VALUE_ACCESSOR,useExisting:t.forwardRef((function(){return i})),multi:!0},{provide:n.NG_VALIDATORS,useExisting:i,multi:!0}],styles:[""]}]}],i.ctorParameters=function(){return[]},i.propDecorators={klass:[{type:t.Input,args:["styleClass"]}],ngClass:[{type:t.Input,args:["ngClass"]}],isRequired:[{type:t.Input,args:["required"]}],isDisabled:[{type:t.Input,args:["disabled"]}],isReadOnly:[{type:t.Input,args:["readonly"]}],placeholder:[{type:t.Input,args:["placeholder"]}],locale:[{type:t.Input,args:["locale"]}],currency:[{type:t.Input,args:["currency"]}],inputN:[{type:t.ViewChild,args:["inputN",{static:!1}]}],min:[{type:t.Input,args:["min"]}],max:[{type:t.Input,args:["max"]}]};var u=function(){};u.decorators=[{type:t.NgModule,args:[{declarations:[i],imports:[r.CommonModule,n.FormsModule,n.ReactiveFormsModule],exports:[i]}]}],e.NgxNumberInputComponent=i,e.NgxNumberInputModule=u,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=ngx-number-input.umd.min.js.map