Skip to content

Commit

Permalink
Merge pull request #43 from pegasystems/mod/tor/US-551958
Browse files Browse the repository at this point in the history
updated decimal field component
  • Loading branch information
4manasa authored Aug 22, 2023
2 parents 279b298 + 30b74c6 commit f263a39
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
<mat-form-field class="psdk-full-width" subscriptSizing="dynamic" [hintLabel]="helperText">
<mat-label>{{ label$ }}</mat-label>
<input
type="text"
matInput
appThousandSeparator
[placeholder]=""
type="number"
step="any"
step="0.01"
[value]="value$"
[required]="bRequired$"
[formControlName]="controlName$"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { Component, OnInit, Input, ChangeDetectorRef, forwardRef } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { FormControl, FormGroup, ReactiveFormsModule, FormsModule } from '@angular/forms';
import { MatInputModule } from '@angular/material/input';
import { MatFormFieldModule } from '@angular/material/form-field';
import { AngularPConnectService } from '../../../_bridge/angular-pconnect';
import { Utils } from '../../../_helpers/utils';
import { ComponentMapperComponent } from '../../../_bridge/component-mapper/component-mapper.component';

import { handleEvent } from '../../../_helpers/event-util';
import { ThousandSeparatorDirective } from '../../../_directives/thousand-seperator.directive';
@Component({
selector: 'app-decimal',
templateUrl: './decimal.component.html',
styleUrls: ['./decimal.component.scss'],
standalone: true,
imports: [CommonModule, ReactiveFormsModule, MatFormFieldModule, MatInputModule, forwardRef(() => ComponentMapperComponent)]
imports: [CommonModule, ReactiveFormsModule, FormsModule, MatFormFieldModule, ThousandSeparatorDirective, MatInputModule, forwardRef(() => ComponentMapperComponent)],
})
export class DecimalComponent implements OnInit {
@Input() pConn$: any;
Expand Down Expand Up @@ -135,16 +136,18 @@ export class DecimalComponent implements OnInit {
this.componentReference = this.pConn$.getStateProps().value;
}

fieldOnChange(event: any) {
// this.angularPConnect.changeHandler( this, event );
this.angularPConnectData.actions.onChange(this, event);
}
fieldOnChange(event: any) {}

fieldOnClick(event: any) {}

fieldOnBlur(event: any) {
// PConnect wants to use eventHandler for onBlur
this.angularPConnectData.actions.onBlur(this, event);
console.log('blur', event);
const actionsApi = this.pConn$?.getActionsApi();
const propName = this.pConn$?.getStateProps().value;
let value = event?.target?.value;
value = value.replace(/,/g, '');
value !== '' ? Number(value) : value
handleEvent(actionsApi, 'changeNblur', propName, value);
}

getErrorMessage() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


import { Directive, ElementRef, HostListener } from '@angular/core';

@Directive({
selector: '[appThousandSeparator]',
standalone: true
})
export class ThousandSeparatorDirective {

constructor(private el: ElementRef) { }

@HostListener('input', ['$event'])
onInput(event) {
console.log('event _onHostListenerInput', event);
const input = this.el.nativeElement as HTMLInputElement;
let value: any = input.value.replace(/,/g, ''); // Remove existing commas
if (event?.data !== '.') {
value = Number(value).toLocaleString(); // Add thousands separator
input.value = value;
}

}
}



0 comments on commit f263a39

Please sign in to comment.