I'm trying to manage a big input by splitting it into single little inputs and populate the big one with keyup, but for some reason when I fire the keyup event the cursor goes to next little input and duplicates the value. The big input is changed and updated correctly, but little ones have problems. I tried also returning the bigvalue from editValue function, but with same result
html:
<div class="form-group">
<label for="prova">Prova input array</label>
<input type="text" class="form-control form-control-sm" id="prova" placeholder="prova" [(ngModel)]="bigvalue" name="prova" maxlength="100">
</div>
<div class="d-flex flex-row" style="overflow-x: auto">
<div *ngFor="let val of bigvalue | arrayfromstring; let i = index;" class="ml-4 my-3">
<label for="value{{i}}">val{{i}}:</label>
<input type="text" class="form-control form-control-sm" id="value{{i}}" name="inputarrayvals" value="{{val}}" (keyup)="editValue(i, $event, bigvalue)" maxlength="1">
</div>
</div>
ts:
bigvalue = "00000000000000000000000000000000000000000000000"
editValue(i, val, item) {
var vals = item.split('')
if (val.target.value.length > 0)
vals[i] = val.target.value
this.bigvalue = vals.join('')
}
Pipe arrayfromstring used to populate little values:
import{ Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'arrayfromstring'
})
export class ArrayFromStringPipe implements PipeTransform {
transform(string: any) {
return string.split('');
}
}