payform icon indicating copy to clipboard operation
payform copied to clipboard

Input event is prevented on auto-formatting

Open slavafomin opened this issue 8 years ago • 3 comments
trafficstars

Hello!

Thank you for this great module!

However, when using auto-formatter and entering the numbers into input field, some events are prevented. This happens right before space character is automatically inserted, e.g. when entering 5213 2…:

  • 5, got events
  • 2, got events
  • 1, got events
  • 3, space is inserted, events are not fired
  • 2, got events …

This makes data-binding to fail, because we can't know when value is changed (I'm integrating it with custom Angular 2+ component).

What could be done about this?

Thanks!

slavafomin avatar Sep 27 '17 12:09 slavafomin

I've managed to work around this issue using the following approach:

inputElement.addEventListener('keydown', () => {
  setTimeout(() => this.propagateValue(inputElement.value), 10);
});

The keydown event is fired every time, so we could rely on it. But the value is not yet updated when it's fired, so we need to wait for some time until it does.

This is kinda ugly, but works.

I would rather listen for input event, which is sealed by the library.

slavafomin avatar Sep 27 '17 13:09 slavafomin

Might be related to #13

Thanks for the report.

jondavidjohn avatar Jul 09 '18 17:07 jondavidjohn

Would not this be resolved by removing this line https://github.com/jondavidjohn/payform/blob/master/src/payform.coffee#L295 or by emitting a new input event at this point? Not sure what issues could this bring

eduarguz avatar Apr 16 '19 16:04 eduarguz