Skip to content

Commit a2e2bff

Browse files
committed
Implemented the feature #19
1 parent 9ccfc6e commit a2e2bff

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

angular-code-input/src/lib/code-input.component.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum InputState {
2626
}
2727

2828
@Component({
29+
// tslint:disable-next-line:component-selector
2930
selector: 'code-input',
3031
templateUrl: 'code-input.component.html',
3132
styleUrls: ['./code-input.component.scss']
@@ -141,7 +142,6 @@ export class CodeInputComponent implements AfterViewInit, OnInit, OnChanges, Aft
141142
}
142143

143144
onInput(e: any, i: number): void {
144-
const next = i + 1;
145145
const target = e.target;
146146
const value = e.data || target.value;
147147

@@ -158,9 +158,18 @@ export class CodeInputComponent implements AfterViewInit, OnInit, OnChanges, Aft
158158
return;
159159
}
160160

161-
this.setInputValue(target, value.toString().charAt(0));
161+
const values = value.toString().trim().split('');
162+
for (let j = 0; j < values.length; j++) {
163+
const index = j + i;
164+
if (index > this._codeLength - 1) {
165+
break;
166+
}
167+
168+
this.setInputValue(this.inputs[index], values[j]);
169+
}
162170
this.emitChanges();
163171

172+
const next = i + values.length;
164173
if (next > this._codeLength - 1) {
165174
target.blur();
166175
return;

0 commit comments

Comments
 (0)