Autotab has a new beta release. Read more here. Documentation changes will be forthcoming to this page once 1.1 has been tested and approved, but until I'm happy with the performance, this page will use 1.1b but contain 1.0 documentation.
Autotab is a jQuery plugin that provides auto-tabbing and filtering on text fields in a form. Once the maximum number of characters has been reached within a defined text fields, the focus is automatically set to the defined target of the element. Likewise, clearing out the text field's content by pressing backspace eventually places the focus on the elements previous target. The purpose of this script is to easily establish auto-tabbing between multiple text fields. It is not intended to support formatting a single text field to a specific need; an example of this is formatting a 10 digit US phone number as (800)555-1234 or a Social Security Number as (123-45-6789).
Download Autotab 1.0 | May 22, 2008 | Dual License: MIT and GPL
Test out the various settings of Autotab below, each noted with their specifications.
<script type="text/javascript" src="jquery.autotab.js"></script>
<form>
<div><strong>Phone Number:</strong></div>
<input type="text" name="area_code" id="area_code" maxlength="3" size="3" /> -
<input type="text" name="number1" id="number1" maxlength="3" size="3" /> -
<input type="text" name="number2" id="number2" maxlength="4" size="5" />
</form>
<script type="text/javascript">
$(document).ready(function() {
$('#area_code').autotab({ target: 'number1', format: 'numeric' });
$('#number1').autotab({ target: 'number2', format: 'numeric', previous: 'area_code' });
$('#number2').autotab({ previous: 'number1', format: 'numeric' });
});
</script>
Autotab allows a certain level of flexibility in how you initialize the auto-tabbing mechanism. Here is a modified version of the above example that will yield the same results:
<form>
<div><strong>Phone Number:</strong></div>
<input type="text" name="area_code" size="3" /> -
<input type="text" name="number1" size="3" /> -
<input type="text" name="number2" size="5" />
</form>
<script type="text/javascript">
$(document).ready(function() {
$('input[name=area_code]').autotab({ target: 'number1', maxlength: 3, format: 'numeric' });
$('input[name=number1]').autotab({ target: 'number2', maxlength 3, format: 'numeric', previous: 'area_code' });
$('input[name=number2]').autotab({ previous: 'number1', maxlength 4, format: 'numeric' });
});
</script>
This example provides the benefit that you have less HTML, but the drawback is that you have to modify your selector and specify the maxlength of the field. Six here, half a dozen there; it comes down to preference.
Comments
Format callbacks
Thanks for this plugin!
Some suggestions:
I'd like to have a filter for (possibly localized) decimal numbers.
How about an option to give a custom formatter callback?
E.g. in your case statement something like this:
...
default:
if (typeof(defaults.format) == 'function')
var val = defaults.format.apply(this, [val]);
break;
...
Also, It'd be nice if the plugin could find a default target using the default tab order on its own, sort of like the fluidTyping plugin.
Interesting feature
I never heard of the fluidTyping plugin, so I decided to check it out and noticed something: when you press backspace in an empty text field, the last character in the previous text field would be removed. I wondered if this was proper behavior or not so I asked two people, who agreed that it seemed proper. I then loaded up an XP install on Virtual PC to see how the product key entry text fields behaved when doing the same actions. My suspicions were correct in that the last character was removed, so I have modified the code to behave this way, which means an Autotab update is coming, but not until I address your other suggestions.
A while back I created two versions of this plugin. The second version works identically to the release, but applying filters was in mass and tabbing was handled automatically. Using the examples listed above:
<script type="text/javascript">
$(document).ready(function() {
$('#area_code,#number1,#number2,#ssn1,#ssn2,#ssn3').autotab_filter('numeric');
$('#alphabet1,#alphabet2,#alphabet3').autotab_filter('alphabet');
$('#alpha1,#alpha2,#alpha3,#alpha4,#alpha5').autotab_filter({ format: 'alpha', no_space: true });
$('#alphanumeric1,#alphanumeric2,#alphanumeric3,#alphanumeric4,#alphanumeric5').autotab_filter({ format: 'alphanumeric', uppercase: true, no_space: true });
$(':input').autotab_magic();
});
</script>
The second version also included various other filtering options, such as symbol/special (!@#$%^&* and so on), money/currency and a different filtering method for alpha. The idea of passing a function is good, but I'll take it a step further so that you could specify a pattern of your own (default.format = 'custom', default.pattern = '[^0-9A-Z]') or pass a function; this should offer a new level of flexibility to the developer, which is always a good thing.
The current state of Autotab makes it difficult to apply previous and next targets to a text field, but if I create functions out of the moving action, or somehow make it possible to alter the targets after the autotab settings have been applied, then this should be doable. Notice in the code above I have a function called autotab_magic(), which does exactly what you're suggesting. I'll get this incorporated somehow in the next release, which will probably be a few weeks off since I'll have a newborn child to tend to very soon.
Thanks so much for the input, I greatly appreciate it!
nice one
This exactly what i was looking for. Thanks for saving my time...
Very userfull post. Nice
Very userfull post. Nice hack
Very nice script
I was looking for something like this, I was not even sure this was possible to do. I love that the Backspace button works :)
Suggestions for next version if you want to update would be to add support for pasting, as of now if I paste in my phone number it only puts in the first part and it does not jump to the next fields automatically.
Thanks a lot.
Guy
An update is coming... eventually
An update is coming, though I have had a number of new projects come up so this has been put on the back burner. Paste support will be added, be sure of that. I want to fine tune it so that it makes sense when people use it, and to give developers the best level of flexibility and customization possible. Sometimes I look at other people's scripts, which are half the size of mine, and wonder what in the world I was thinking! Thanks for your feedback, I really appreciate it!
Numeric with decimal
I was trying numeric which doesnt allow decimal. So i just add
case 'decimalNumber':
var pattern = new RegExp('[^0-9\.]+', 'g');
var val = val.replace(pattern, '');
break;
Can someone give me a regualer expression which just allow a number followed by dot and than a number (22.4 / 22.34)
it should not allow (23. / 23.43.24 etc)
This one's tricky
I'm not an expert by any stretch of the imagination with regular expressions, but I always like to jump at the opportunity to expand my knowledge of them. I like to use The Regex Coach to test out any expressions that I may need to create, and I was able to create something that would work in a language other than JavaScript. What I ended up with is:
[0-9,]+[.]+[0-9]{2}If the string in question is 23,192.168.531.110, the above expression would return 23,192.16, but like I noted, this won't work in JS. I did some searching for floating number regular expressions, but none of the many I tried were able to work properly; still, this shouldn't discourage you from searching and tinkering yourself. A second way to do it is to split the string up by the decimal and then join the first and second items together after applying, but this isn't ideal; another way would be to parseFloat() on the string, but again, this is not ideal. I'll see if there's a way that I can have this work properly, though the point of this script is to split fields up by characters such as a decimal point, so you'd end up with something like:
.
Very Nice Job
Good Luck!!!
more unobtrusive way?
I wish there was a way to say whenever a max length of a field is reached to tab to the next field.
That way you don't need to keep track with field names etc.
Filtering a field is should be separate then autotabbing.
Any suggestions?
Greg
You want unobtrusive? You got it!
The filter method in Autotab is optional, so you could define what the target and previous elements are without filtering any of the text. However, if you want to eliminate the clutter, then you can apply a function I mentioned in my first comment at the top. Add the following to jquery.autotab.js:
$.fn.autotab_magic = function(focus) { var children = this; var count = this.length; this.each(function(i) { var n = i + 1; var p = i - 1; if(i > 0 && n < count) $(this).autotab({ target: children[n], previous: children[p] }); else if(i > 0) $(this).autotab({ previous: children[p] }); else $(this).autotab({ target: children[n].id }); // Set the focus on the specified field ID if((isNaN(focus) && focus == $(this).attr('id')) || (!isNaN(focus) && focus == i)) $(this).focus(); }); };To utilize this function:
<script type="text/javascript"> $(document).ready(function() { $(':input').autotab_magic(); }); </script>As an added bonus, you can pass the array key of :input or the element's id to apply focus on that element:
$(':input').autotab_magic(0);
// OR
$(':input').autotab_magic('username');
you write:
you write: "((isNaN(focus) && focus == $(this).attr('id')) || (!isNaN(focus) && focus == i))"
so this "isNaN" must be case sensitive or not?
JS is, but isNaN is not, case-sensitive
isNaN is not case-sensitive because it does not matter what you pass to it because isNaN is used to determine if the value is a number or not. However, JavaScript is case-sensitive, and if your field id is username, but you pass Username, jQuery will not apply focus to the field because #Username does not exist.
Autotab download
Your link is broken to download the source...
Link fixed
Thanks for the heads up.
Link Broken Again
Nice script, but download link doesn;t work.
please provide mirror if your host is down.
Doh!
When I updated the link, I didn't provide a leading slash and as a result, it was looking for the file under /sandbox/jquery-autotab, which isn't a true path. I should setup some kind of mirror though...
Slight problem
Slight problem with your "Do not auto tab when the following keys are pressed" test.
var keys = [8, 9, 16, 17, 18, 19, 20, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 144, 145];
var string = keys.toString();
if(string.indexOf(key(e)) == -1 && val.length == defaults.maxlength && defaults.target)
I don't think that's doing what you think it's doing... What it's actually checking is whether key(e) is inside the string anywhere, so if you removed 9 from the keys array, it will would still match the 9 in 19, and give the wrong result.
You're probably after the $.inArray function
var keys = [8, 9, 16, 17, 18, 19, 20, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 144, 145];
if($.inArray(key(e),keys) == -1 && val.length == defaults.maxlength && defaults.target)
That is a problem
That's a good point that I hadn't considered. I'm going to implement $.inArray() with my next update of Autotab, which I'm hoping to have ready in a few days. Thanks :)
Left arrow key doesn't work in IE 7
Nice plug-in, but I've noticed a big issue in IE 7 (haven't tried IE 6 or lower). As far as I can tell, everything else works fine, but when you use the left arrow key, the cursor moves left briefly and then jumps to the end of the text box. Basically, there's no way to use the left arrow key in IE! Also, I've noticed that when you use backspace to move the previous field, the cursor initially goes the start of the previous text box before jumping to the end. That behavior is strange but not as problematic as the first issue. I see the same behavior for both issues both here in your samples as well as in my own test page.
Actually, I just checked Safari and see the same issue with the left arrow key. Interestingly, in that browser, the backspace doesn't work at all--the cursor doesn't move to the previous field.
Thanks,
Drew
I'll look into those
Thanks for the feedback. I'll look into the issue when I get a chance, and it's strange that it doesn't appear to work in Safari. As far as IE is concerned, the cursor going to the front of the text box to the end is an IE behavior, unlike other browsers where the cursor appears at the end from the start. Today's a hectic day, but maybe in the next few days I'll have an update to address this issue.
I tend to dislike auto-tab
I tend to dislike auto-tab behavior because I expect these behaviors to work because I use them all the time:
A. 223 backspace 2
B. 222 tab 111 tab 0000
C. 223 1 shift-tab 222
I'm using Safari 4 on a Mac, so it sounds like A is expected to work on most browsers. Could it be an issue with backspace vs delete?
For B, perhaps have a short timeout immediately after you auto-select the next field and suppress the tab key during that period of time?
Alternatively for B, you might select the next field only when the 1 is pressed (i.e. the field 'overflows'), but this gives no affordances that auto-tab is present. In the end it won't help most users, instead catching only those who overlook the fact that there are multiple fields.
For C - not sure why you're changing the standard behavior (selecting the full field); probably a by-product of attempting to get expected backspace behavior.
Still, I don't see what the appeal of separate fields is in the first place. If you're simulating the behavior of a single field, why not avoid auto-tab issues altogether and allow a user to enter their phone number however they like into one text input? (222) 111-0000 or 222-111-0000 or 2221110000. You can validate it as easily as anything else (just strip out the punctuation first).
Anyway, if for some reason you are constrained to using multiple text fields, this auto-tab implementation is one of the better ones I've come across. If only the behaviors listed above worked as I expect them to. Keep it up!
Addressing the issues
I tried following the steps you detailed but I'm not sure I completely understand, so if you could post back and elaborate, that would be helpful. A sounds like you're describing the proper behavior of any autotabbing system. With B, I could possibly ignore the Tab key, so I'll see what I can do about it. With C, that's the standard behavior of any browser, and possibly any program. It may in fact be tied to the OS behavior because it happens when focusing on a text item that has content, regardless of pressing Tab or Shift+Tab. I can possibly replace the text in a field with its current text when Tab or Shift+Tab are pressed, but it's not really necessary and goes against the native behavior.
The appeal for separate fields is to have a tighter leash on what users input into your form. Unfortunately, you have to assume that your end user has a dullness of perception and will try to include anything and everything that they so want. In one case, I had someone enter their Social Security Number like so: 123=45=6789. A simple regular expression would clean this up and you could then validate the length, but the point is show the user what they can and cannot do immediately instead of having them fill out a large form and have half the items be incorrect. There's also formatting information to your, or a superior's, liking. It's easy with a phone number to split the string up so as to achieve a consistent format of 123-456-7890, but the uses for an autotab/filter script are virtually endless as they vary with the needs of the item in question.
Thanks for your feedback though, I'll gladly take any criticism and feedback to make this the best autotab script around.
Ignoring unintended tabs
I strongly agree with the suggestion to ignore unintended tabs. I'm admittedly somewhat Spartan and would be happy with just a single text box for entering phone and credit card numbers, but I generally dislike forms that auto-tab because I instinctively tab between form elements already, so it only slows me down having to then correct myself. (I do think auto-tabbing is a nice feature for most people, just too few forms that I fill out use it, so it always throws me off. :)
I'd like to suggest that if the first key press after Autotab changes focus between form elements is a tab and occurs within half a second or so, then it should be ignored. This would make my use case a lot less frustrating, while maintaining the usefulness for people who don't explicitly tab between elements, and not otherwise gratuitously impairing the functionality of the tab key while filling out forms.
Your point is good about auto
Your point is good about auto tabbing not always being the most intuitive experience. Your solution however doesn't work because people will push tab-tab-tab to navigate quickly through the items.
I'd love to see a second version of this plugin that doesn't auto tab at all but lets you specify the tab order. This is something that is hard to accomplish in some scenarios and is great to be able to manually specify the order in these cases.
That wouldn't be auto-tabbing
What you're describing wouldn't be considered an auto-tab script because no tabbing is occurring. It's definitely doable and would require a few changes. The first is to check the keystroke. If it's tab, then you would execute the focus command located at the bottom of the script (keyCode is 9).
When I said "Autotab changes
When I said "Autotab changes focus", I meant only times when Autotab changes focus in a way different than how the browser would behave if Autotab was not being used. If a user presses tab-tab-tab under the scheme I described, only the first tab would possibly be ignored as redundant.
I'll see what I can do
I haven't had a chance to look into this yet, but it's on my todo list.
thanks
This exactly what i was looking for. Thanks for saving my time...
autotab does not work when a pdf is open
Here is description of scenario.
Generally autotab for three numeric fileds ( in A.JSP) work perfectly fine. however in the same browser if a PDF is opened in other portlet ( in B.JSP), it loses the autotabbing feature.
Regular syntax used here is,
I need more information
What browser are you using? What OS? What PDF reader do you use? Do you have a site that I can view this on? Are you viewing the PDF in the browser or in a separate application? Having a PDF open in a browser causing the autotab script to not work sounds like an issue with the browser.
autotab jumps to 3rd textbox instead of 2nd
I am looking for a way where auto tab works even if values entered very fast. I tried the above case too, if user enters number really fast the auto tab jumps to 3rd text box instead of 2nd. putting a timer helps but not in different browsers and versions and when page is loading. Is there any way to do this?
Input needed
During my constant testing I would type as far as I could and never once encountered the behavior you're describing. What browser and version are you using?
I see what he means...
To re-create the auto-tabbing to the third field in the phone number, first fill in all fields, start at the first, and then type something really fast like "123." I was working on a feature similar to your auto-tab (before I came across this plugin) and had the same bug. The issue is inside of the keyup callback "this" will sometimes refer to the wrong field. Sad huh?
Odd - but frustrating problem...
I have a small problem - I am using your auto-tab function to do its stuff in a payment form - autotabbing through the credit card field etc.... I am using the max length field as described and it all works almost... When a user selects AMEX from the card type drop down, I use jquery to reissue your autotab commands with a shorter lenght for the credit card field and a longer lenght for the CCV. I have similar for Diners (card lenght 14 instead of 16) and Diners CCV is the same as Visa and MC at 3. Now the odd thing it ALL works -for all the different card types etc, except for the change in CCV for the AMEX from 3 to 4.... it is really starting to bug me as I cant seem to finger what is wrong - especially when the variable length Credit Card numbers work....
here is the sample jquery:
if($('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_DropDownListCreditCard').val() == "AmericanExpress")
{
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber1').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber2', maxlength: 4 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber2').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber3', maxlength: 4 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber3').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber4', maxlength: 4 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber4').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCMonth', maxlength: 3 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCMonth').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCYear', maxlength: 2 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCYear').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CSC', maxlength: 2 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CSC').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_TextBoxCardHolderName', maxlength: 4 });
}
else if ($('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_DropDownListCreditCard').val() == "Diners")
{
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber1').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber2', maxlength: 4 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber2').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber3', maxlength: 4 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber3').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber4', maxlength: 4 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber4').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCMonth', maxlength: 2 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCMonth').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCYear', maxlength: 2 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCYear').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CSC', maxlength: 2 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CSC').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_TextBoxCardHolderName', maxlength: 3 });
}
else
{
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber1').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber2', maxlength: 4 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber2').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber3', maxlength: 4 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber3').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber4', maxlength: 4 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCNumber4').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCMonth', maxlength: 4 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCMonth').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCYear', maxlength: 2 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CCYear').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CSC', maxlength: 2 });
$('#ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CSC').autotab({ target: 'ctl00_cphMainMemberContent_signup1_CreditCardInfo1_TextBoxCardHolderName', maxlength: 3 });
}
FYI the credit card number is broken into 4 imputs and the CCV is ctl00_cphMainMemberContent_signup1_CreditCardInfo1_CSC again just an input. The Card Holder Name is a asp.net Text Box, but i figure that by the time jquery is seeing it - it has been rendered as an input anyway...
Do you have any ideas????
That's strange
Sorry for not responding sooner (two weeks?!), but I was able to replicate the problem you're describing. The value being passed is ignored and the one hardcoded is used instead, which doesn't make sense. I'll have to play around with it some more and see what I find out.
Blur Event
Wonderful script - thank you.
However, I was writing a simple form validation script that relied on the
blur();method, which this auto-tab plug-in does not trigger when it hops from field to field.Simple enough fix, though: insert
this.blur();right before each instance of bothdefaults.previous.focus();&defaults.target.focus();(three total, I believe). Now my blur() handlers are called when the fields auto-tab.Man I love jQuery!
Good idea, I'll explore it
I don't see any issue with calling the blur event, though logic tells me that blur events should trigger whether I manually call it or if I change focus. I'll have to explore this to see the benefits and drawbacks, such as: does one browser automatically call the blur event when the focus is changed? Will adding a manual blur call make the blur events run twice? I'll have to test this and decide from there. Thanks for the feedback! :)
Idea: Sentence case...
Firstly, I'd like to say "WOW! Great script!!" - I love it, and it works great!!
However, it would be nice if it could also do "Sentence Case". So converting first character to upper-case and remainder characters to lower-case. This could might be handy for 'First Name', 'Last Name', 'City' type of input fields. Hence when the user types in "sandra" it could use Ajax to convert the first letter into upper-case and leaving the rest alone, ex: "Sandra"
Adding some additional smarts, you could also have it capitalize every first character of a sentence. So in a text box which allows the user to type in a comment or something would automatically convert the first character into upper-case where it resides before a period ".", example: "this is a test. xbox rules!" would be converted to "This is a test. Xbox rules!"
This link has this, which would be nice to include it into your Ajax/jQuery plugin: http://javascript.internet.com/forms/sentence-case.html
Can't wait to try your next creation! Cheers.
If you use auto-tab; PLEASE test it with your users
It looks Mr. Miller has put a lot of effort (and thought) into implementing his Autotab plugin. It is great to see that effort shared with the world. So I'm hesitant to say anything that would discourage efforts like this . . .
But, from the Blog comments at least, I strongly suspect that most of the developers reading this Blog item have no idea that the auto-tab concept has a long (actually, VERY long) history in the computer world. More to the point, auto-tab is, at best, highly controversial; more typically (especially by experts in usability and interaction design), it is considered a bad idea.
There are a small number of usage scenarios where auto-tab is a clear win. These involve: high-speed, repetitive, data-entry over a reasonable number of data entry forms/pages, by trained data entry clerks. By 'clear win', I mean that the efficiency gains over the long term outweigh the short term costs in usability (especially data entry errors).
For all other usage scenarios, the disadvantages of auto-tab strongly outweigh the advantages. This is especially true if your usage scenario involves any of the following: a heterogeneous or very large user population (a lot of Web sites would fall into this category); users who are not fluent at data entry; users who are unfamiliar with auto-tab or are unused to it (because most forms/pages don't work that way).
For example, what often happens (with auto-tabbing enabled on one or more fields) is that you get a lot of form submissions where the values in each field are offset by 1 (or more) fields, because the user didn't notice the auto-tab behavior and just kept typing (and hitting the Tab key, as they 'expect' to).
Bottom line: Just DON'T--use auto-tab, that is.
Sorry about that,
Banned
Thanks for your Overview
very helpful stuff here.When it comes to simpler user experience, having your form validation happen instantly on the same page is a lot cleaner than reloading pages and possibly losing some form content. In this tutorial I'll show you how to use jQuery to do some instant checking on an example comment form.
mask
how i can use this plugin with jquery mask plugin?
Will look into this
I've never heard of mask, but I will see if there's a way for them to coexist.
should make "copy-paste"-able
should be able to copy and paste. and use mask for input instead of removing numbers. other than that. nice!
Copy-n-paste will come
Copy-n-paste will come eventually, but I'm not sure what you mean by "mask for input instead of removing numbers." Can you elaborate?
use this plugin with jquery mask plugin
I use this plugin with jquery mask plugin with not problems at all, it is a great plugin.
Andy
Code revisions and suggestions for 1.1b
Excellent plugin, very well done. I offer several comments to help keep this plugin at its best.
For the record, my test base for the following is Autotab 1.1b (rev. 2008-09-10), jQuery 1.2.6 (rev. 2008-05-24), Firefox 2.0.0.20, and Windows XP SP2. That said, these comments reflect Autotab's interaction with the jQuery core and thus apply across platforms.
I have two suggestions regarding the selection of input elements based on their 'name' attribute. Unfortunately, at least in 1.1b, this method is broken.
1) On a somewhat syntactical note, the best-practice technique for selecting objects by name uses quotes (single or double) to delineate the name. This can be seen in the official jQuery example of such a selection at <http://docs.jquery.com/Selectors/attributeEquals#attributevalue>. In the case of Autotab, the problem arises on line 19 of 1.1b. Updated code should read:
var check_name = $('input[name="' + name + '"]');
2) Unfortunately, that is not what is preventing the selection of input elements by their 'name' attribute. Rather, the tests for a defined object on lines 21 and 23 of 1.1b are not valid. The jQuery model of element selection does not, although one might anticipate it, return 'undefined' when no object is found for a given criteria. It instead returns a valid jQuery object of length 0. Thus, in order to determine whether a valid element was indeed found, one needs to check the jQuery object for non-zero length.
It is obvious immediately that checking for an element by ID should give only one result when valid, as element IDs are supposed to be unique. It is less obvious whether checking for an element by name requires length to be 1 or just greater than zero. However, the way that the previous and target objects are focused automatically (lines 219 and 251, respectively) suggests that a test for length 1 is the correct approach, since otherwise the last element in the jQuery object array would get focus instead of any others. Although this may be the desired effect in some cases, it is imprecise and unpredictable.
Updated code on lines 21-24 should read:
if(check_id.length == 1)
obj = check_id;
else if(check_name.length == 1)
obj = check_name;
This is actually more efficient in some ways because now the if-test on line 250 will fail for invalid IDs and names (since defaults.target = null), instead of trying to set focus on an inexistent element.
On a different note, I also wrote a very small addition to implement the ignoring of tabs following a field advancement by Autotab, as proposed by Matthew Dempsky in his thread of October 7, 2008. As a heavy web user I tab through many forms daily, and often auto-tab implementations will mess up my form entry (as explained by Banned in Boston in his thread of November 4, 2008). However, a customer for whom I am currently developing a proprietary system demands auto-tab in telephone entry which, for usability and historical reasons related to the customer's databases, must remain as three separate fields.
This implementation uses a half-second delay period in which it ignores the tab key, only after Autotab automatically advances to a target. The normal "tab-tab-tab" progression is never affected. In my tests, I found one half-second to be a good duration, although it can obviously be altered quite easily.
The function to cancel a tab call is short and sweet, and I inserted it on line 28 of 1.1b, immediately following the check_element function definition. Note that I use the event.keyCode call because of its clarity (and as used in jQuery standards, see <http://docs.jquery.com/Events/keyup#examples>), but the use of 'keyCode' vs. 'which' comes down to developer preference.
// Stop action of tab key
function stop_tab(e) {
if(e.keyCode == 9) {
return false;
}
};
The magic happens with a call to bind the stop_tab function on keydown to the target field after an "autotab", and a timeout to unbind the function after 500ms. The following code replaces lines 250-251:
if($.inArray(e.which, keys) == -1 && val.length == defaults.maxlength && defaults.target) {
defaults.target.focus().bind('keydown',stop_tab);
setTimeout(function() { defaults.target.unbind('keydown',stop_tab); }, 500);
}
Lastly, it would be great to include a packed version of Autotab for production environments along with the source. This saves developers using Autotab the hassle of packing the source for their clients each time they download Autotab. In fact, having one packed version available on the site as a production release, and then a separate optional download of the unpacked source, would save you bandwidth costs as well.
The optimal packing tool right now seems to be Yahoo!'s YUI Compressor <http://developer.yahoo.com/yui/compressor/>, as supported by size calculations and in tests with Autotab. Packing Autotab 1.0, I got an output file 39% the size of the original. Packing my (modified) version of 1.1b, I got an output 34% the size of the original! Compare this to the conservative (non-regressive) setting of JSMin, which downsizes to only 43% of the original size of 1.1b. Coincidentally, YUI Compressor is also recommended by the jQuery folks (see <http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_compress_my_code.3F>).
Thanks for all your great work, and I look forward to the next release!
Some great comments and suggestions
Those are some great comments and suggestions Zack. Thank you! You'll be seeing these implemented in the next release, though I've been pretty swamped with work, side work and my 360, but it's hard to argue against what you've listed.
iPhone Support
Hi, I came across this article when looking to implement this solution for a web application I am developing specific to the iPhone. I have implemented autotab and it is running fine in all my desktop web browsers.
However, due to the iPhone's keyboard which hides when a field loses focus the auto tab doesn't move to the next field. Would it be possible to implement a check to determine in the user is using an iPhone and make this work on this platform?
Very good but....
This plugin is really good but I found some restrictions with it. for example the "@" "." etc signs are not enabled, as a result I couldn't use the script on that particular text field.
Additionally it doesn't move automatically towards input boxes nor it allows to move to the text box if a cursor is on the multi-areabox. It just loops within areabox and doesn't go any further, even after giving character limit.
I did read where it mentioned something about "@" and other characters however I didn't understand how to implement it.
Any ideas?
Rest its all good
Many thanks
Regards
Jehanzeb
Post new comment