0

When I change a value in an input field, (58.10) to (58.1), the cursor goes behind 5 as soon as I remove "0". I expect it to be beside "1".

React:

// Props
var data = [
  {unit_amount: 58.10, id: 1},
  {...},
  {unit_amount: 25.99, id: 3},
]

_valueChange(i, e){
  e.preventDefault();
  var obj = this.props.data;
  var num = obj.find(p => i === p.id);

  num.unit_amount = e.target.value;
},

// Render

var lineItems = this.props.data.map(function(l){
  return(
   <tr key={l.id}>
    <input type="number" value={l.unit_amount} onChange={this._valueChange.bind(this, l.id)} />
   </tr>
  )
})

Value changes ok but the cursor (the "pipe") goes to the extreme left once I hit the backspace button once. Any ideas?

Sylar
  • 11,422
  • 25
  • 93
  • 166

1 Answers1

0

It possible to set the cursor position after the value is set, just find the length of the string and set the cursor position to the length of the string.

Check this post out for the APIs your looking for. Get caret position in HTML input?

Community
  • 1
  • 1
Sten Muchow
  • 6,623
  • 4
  • 36
  • 46