Skip to content

Commit

Permalink
chore:🌻 remove directive from dom
Browse files Browse the repository at this point in the history
  • Loading branch information
NsdHSO committed Oct 28, 2023
1 parent 78c375a commit 7045692
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
<div class="sivan-input-container__center-label"></div>
<div class="sivan-input-container__field">
<input
sivanMask
typeMask="europe"
[formControl]="mainControl"
[placeholder]="hintTop"
class="input-dropdown text"
Expand Down
14 changes: 13 additions & 1 deletion ftx-sivan-shared/src/lib/directive/mask.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MaskDirective } from './mask.directive';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, DebugElement } from '@angular/core';
import { Component, DebugElement, ElementRef } from '@angular/core';
import { By } from '@angular/platform-browser';

@Component({
Expand Down Expand Up @@ -29,6 +29,18 @@ fdescribe('MaskDirective', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [TestComponent],
providers: [
{
provide: ElementRef,
useValue: {
nativeElement: {
value: {
toString: () => '',
},
},
},
},
],
});
});

Expand Down
10 changes: 8 additions & 2 deletions ftx-sivan-shared/src/lib/directive/mask.directive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
AfterViewInit,
Directive,
ElementRef,
HostListener,
Expand Down Expand Up @@ -40,13 +41,18 @@ export class MaskDirective {
}
}

ngAfterViewInit(): void {
if (this.elementRef.nativeElement.value) {
this.onInput(this.elementRef.nativeElement.value.toString());
}
}

@HostListener('input', ['$event.target.value'])
onInput(value: string) {
// Remove any non-digit characters
value = value.replace(/\D/g, '');

// Format the value according to your requirements
const formattedValue = this.formatValue(value, this.typeMask);
const formattedValue = this.formatValue(value.toString(), this.typeMask);

// Update the input value with the formatted value
this.renderer2.setProperty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ export class SpendMoneyComponent {
} as DataFormBuilder;

constructor() {
this.simple = this._fb.buildFormFromJson(this.simpleData);
this.simple = this._fb.buildFormFromJson({
label: 'name',
value: 412123,
validators: [{ type: TypeConstantEnum.REQUIRED }],
placeholder: 'Isvan Avramescu',
labelHint: 'Name for User',
updateOn: 'blur',
});
this.currency = this._fb.buildFormFromJson({
label: 'personalData',
labelHint: 'Personal Data',
Expand Down

0 comments on commit 7045692

Please sign in to comment.