Mathachew / jquery-autotab

A jQuery plugin that provides auto tabbing and filtering on text fields in a form
http://autotab.mathachew.com/
366 stars 98 forks source link

2 characters when used with jQuery autoNumeric #61

Open PearDorors opened 10 years ago

PearDorors commented 10 years ago

I use autoNumeric https://github.com/BobKnothe/autoNumeric for ensuring numeric and currency on a page. When used with autotab-1.1b and the $(document).ready(function () { $(':input').autotab_magic();
}); it worked fine together. However, upgrading to the new version 1.7.1 and using the newer $(document).ready(function () { $(':input').autotab();
}); it still enforces currency and numeric, but I get 2 characters for every key press. So '3' becomes '33' and '6' becomes '66', etc.

Mathachew commented 9 years ago

Autotab and autoNumeric both perform similar actions in filtering the text box's value and setting only characters that are allowed. Things can get tricky because autoNumeric might be throwing in commas, periods and special characters, which will definitely have an odd effect on the behavior of Autotab after the maxlength is reached or exceeded. I don't think there's anything that can be done to address this, unfortunately. You might want to add in your own basic auto tabbing functionality through a callback.

agrath commented 8 years ago

I ran into this issue also. In my case, I have implemented autotab before and know how many edge cases there are for handling paste, forward/back etc. In my case, I wanted autonumeric to support min/max but had the double entry issue.

To solve it, I have patched my version of autoTab. I am not sure if this should be included but am happy to submit a PR if you think it should @Mathachew Using these two controls together is definitely an edge case of sorts, since it really shouldn't be up to either control to be aware of the other, but there is a clash in functionality.

1) Initialize as follows: $('.timefield-exact input[type=text]').autotab('filter','number').autotab({ tabOnSelect: true }); $('.timefield-exact input[type=text]').autoNumeric('init', {}); [note: I can't combine tabOnSelect and filter into the same object, not sure why. Comes through as filter:all if I init as { filter: 'number', tabOnSelect: true } ] 2) In autotab keypress.autotab check to see if the input is initialized with autonumeric. If it is, bypass the value splice code but still internally parse the value and use it to figure out if this key would have been valid to initiate the tab (after autonumeric adds the character)