Skip to content

Commit 9e01ea8

Browse files
author
jitender
committed
1 parent 9ed65e2 commit 9e01ea8

File tree

4 files changed

+9
-34
lines changed

4 files changed

+9
-34
lines changed

projects/ng-otp-input/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng-otp-input",
3-
"version": "2.0.6",
3+
"version": "2.0.7",
44
"description": "A fully customizable, one-time password input component for the web built with Angular.",
55
"author": {"name": "jitender"},
66
"homepage": "https://github.com/code-farmz/ng-otp-input#readme",

projects/ng-otp-input/src/lib/components/ng-otp-input/ng-otp-input.component.spec.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

projects/ng-otp-input/src/lib/components/ng-otp-input/ng-otp-input.component.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,8 @@ export class NgOtpInputComponent implements OnInit, AfterViewInit,OnDestroy,Cont
9090
}
9191
}
9292
writeValue(value: string): void {
93-
this.currentVal = value || null;
94-
if (this.otpForm && this.currentVal) {
95-
this.setValue(this.currentVal);
96-
}
93+
this.currentVal = !this.hasVal(value) ? null : value;
94+
this.setValue(this.currentVal);
9795
}
9896

9997
registerOnChange(fn: any): void {
@@ -164,8 +162,11 @@ export class NgOtpInputComponent implements OnInit, AfterViewInit,OnDestroy,Cont
164162
}
165163

166164
}
165+
hasVal(val){
166+
return val != null && val != undefined && (!val?.trim || val.trim() != '');
167+
}
167168
onInput($event,inputIdx){
168-
let newVal=this.currentVal ? `${this.currentVal}${$event.target.value}` : $event.target.value;
169+
let newVal=this.hasVal(this.currentVal) ? `${this.currentVal}${$event.target.value}` : $event.target.value;
169170
if(this.config.allowNumbersOnly && !this.validateNumber(newVal)){
170171
$event.target.value=null;
171172
$event.stopPropagation();
@@ -257,8 +258,8 @@ export class NgOtpInputComponent implements OnInit, AfterViewInit,OnDestroy,Cont
257258
if (this.config.allowNumbersOnly && isNaN(value)) {
258259
return;
259260
}
260-
this.otpForm.reset();
261-
if (!value) {
261+
this.otpForm?.reset();
262+
if (!this.hasVal(value)) {
262263
this.rebuildValue();
263264
return;
264265
}

src/app/app.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export class AppComponent {
3232

3333
}
3434
onOtpChange(otp) {
35-
console.log(otp);
3635
this.otp = otp;
3736
}
3837

0 commit comments

Comments
 (0)