omarshammas / jquery.formance

A jQuery library for formatting and validating form fields, based on Stripe's jQuery.payment library.
omarshammas.github.io/formancejs
Other
632 stars 105 forks source link

Tests are failing on restrictNumeric and restrictAlphaNumeric #4

Open omarshammas opened 11 years ago

omarshammas commented 11 years ago

The tests are failing, but in practice it works.

omarshammas commented 11 years ago

It appears that triggering the keypress event using js is not the same as clicking the input field and pressing 4.

$number = $('<input />').val('123')

e = $.Event('keypress')
e.which = 52 # 4
$number.trigger(e)

assert_equal '1234', $number.val()

So you may be wondering why do the tests pass on the other fields even though their formatters are also listening to the keypress event?

Even though they're listening for the keypress event, the value of the field is modified directly. For example the data formatter does

$target.val("#{val} / ")