New input control for Transaction Amounts
This commit is contained in:
committed by
Jose Alberto Hernandez
parent
83f9a0e499
commit
9b51ec4694
@@ -0,0 +1,21 @@
|
||||
<mat-form-field appearance="fill" fxFlex="100%" *ngIf="isRequired">
|
||||
<mat-label>{{'labels.inputs.' + inputLabel | translate}}</mat-label>
|
||||
<span matTextSuffix class="m-l-10">{{ currency.code }}</span>
|
||||
<span fxFlex="auto"></span>
|
||||
<input mifosxFormatAmount="{{currency.code}}:{{currency.displaySymbol}}" class="right-input"
|
||||
[formControl]="inputFormControl" (keypress)="numberOnly($event)"
|
||||
required matInput (blur)="displayHint = false;" (focus)="displayHint = true;" />
|
||||
<mat-error *ngIf="inputFormControl.hasError('required')">
|
||||
{{'labels.inputs.' + inputLabel | translate}} {{ "labels.commons.is" | translate}} <strong>{{
|
||||
"labels.commons.required" | translate}}</strong>
|
||||
</mat-error>
|
||||
<mat-hint class="right-hint" *ngIf="displayHint">{{inputFormControl.value | currency:currency.code:currency.displaySymbol:'1.2-2'}}</mat-hint>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="fill" fxFlex="100%" *ngIf="!isRequired">
|
||||
<mat-label>{{'labels.inputs.' + inputLabel | translate}}</mat-label>
|
||||
<span matTextSuffix class="m-l-10">{{ currency.code }}</span>
|
||||
<span fxFlex="auto"></span>
|
||||
<input mifosxFormatAmount="{{currency.code}}:{{currency.displaySymbol}}" class="right-input"
|
||||
[formControl]="inputFormControl" (keypress)="numberOnly($event)" matInput (blur)="displayHint = false;" (focus)="displayHint = true;" />
|
||||
<mat-hint class="right-hint" *ngIf="displayHint">{{inputFormControl.value | currency:currency.code:currency.displaySymbol:'1.2-2'}}</mat-hint>
|
||||
</mat-form-field>
|
||||
@@ -0,0 +1,21 @@
|
||||
.expandcollapsebutton {
|
||||
margin-top: -7px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 37rem;
|
||||
}
|
||||
|
||||
.right-input {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.right-label {
|
||||
padding-right: 25px !important;
|
||||
}
|
||||
|
||||
.right-hint {
|
||||
min-width: 100%;
|
||||
text-align: right;
|
||||
font-weight: 500;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { InputAmountComponent } from './input-amount.component';
|
||||
|
||||
describe('InputAmountComponent', () => {
|
||||
let component: InputAmountComponent;
|
||||
let fixture: ComponentFixture<InputAmountComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ InputAmountComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(InputAmountComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { Currency } from '../models/general.model';
|
||||
import { UntypedFormControl } from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'mifosx-input-amount',
|
||||
templateUrl: './input-amount.component.html',
|
||||
styleUrls: ['./input-amount.component.scss']
|
||||
})
|
||||
export class InputAmountComponent implements OnInit {
|
||||
|
||||
@Input() isRequired = false;
|
||||
@Input() currency: Currency;
|
||||
@Input() inputLabel: string;
|
||||
@Input() inputFormControl: UntypedFormControl;
|
||||
|
||||
displayHint = false;
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
numberOnly(event: any): boolean {
|
||||
const charCode = (event.which) ? event.which : event.keyCode;
|
||||
if (charCode === 46) {
|
||||
if (!(this.inputFormControl.value.indexOf('.') > -1)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else if (charCode > 31 && (charCode < 48 || charCode > 57)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inputBlur(): void {
|
||||
this.displayHint = false;
|
||||
}
|
||||
|
||||
inputFocus(): void {
|
||||
this.displayHint = true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user