jquery-autotab
v1.9.2
Published
A jQuery plugin that provides auto tabbing and filtering on text fields in a form
Downloads
404
Readme
jQuery Autotab
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 text field, the focus is automatically set to a defined element. Likewise, clearing out the text field's content by pressing backspace eventually places the focus on a previous element.
Why jQuery Autotab?
- Auto tabbing behaves logically, in both tabbing forward and tabbing backwards.
- Allow your users to easily modify your text in a tab that would otherwise auto tab away.
- Reduce the amount of bad data submitted in a form by filtering text fields.
- Populate multiple text fields by pasting into one.
- Enhance text fields by auto tabbing when a specific character is pressed.
- It is small, fast, easy to load and built on the powerful jQuery library.
Demo
Always running the latest and greatest version of Autotab: http://autotab.mathachew.com/
Angular and Knockout demos are also available.
Table of Contents
- Requirements
- Installation
- Setup and Usage
- Options
- Filter Formats
- Known Issues
- Minify
- Feedback
- Copyright and License
Requirements
Autotab works in both jQuery 1.7+ and 2.x. If your site supports Internet Explorer 6, 7, and/or 8, use jQuery 1.7+ since 2.x drops support for these browsers.
Installation
Add a reference to jquery.autotab.js.
<script src="jquery.autotab.js"></script>
Setup and Usage
Autotab can be setup in several different ways within jQuery's $(document).ready()
event. The two components that make up Autotab, auto tabbing and filtering, can be managed independently from one another, providing numerous ways of achieving the same result, depending on how indepth you want to setup your form.
Auto Tabbing
Note: If the selector matches multiple elements, the target and previous fields will be overwritten if previously set.
Examples
Establishes auto tabbing rules only and forces each field to have a maxlength
of 1.
$('.answer').autotab({ maxlength: 1 });
<div>
<label>Answer 1</label>
<input type="text" id="answer1" class="answer" size="3" /> -
<label>Answer 2</label>
<input type="text" id="answer2" class="answer" size="3" /> -
<label>Answer 3</label>
<input type="text" id="answer3" class="answer" size="3" /> -
</div>
Automatically establishes auto tabbing order and number filtering.
$('.number').autotab('number');
<div>
<label>Phone Number</label>
<input type="text" id="number1" class="number" maxlength="3" size="3" /> -
<input type="text" id="number2" class="number" maxlength="3" size="3" /> -
<input type="text" id="number3" class="number" maxlength="4" size="5" />
</div>
Manually defines auto tabbing order and alphanumeric filtering.
$('#alphanumeric1').autotab({ format: 'alphanumeric', target: '#alphanumeric2' });
$('#alphanumeric2').autotab({ format: 'alphanumeric', target: '#alphanumeric3', previous: '#alphanumeric1' });
$('#alphanumeric3').autotab({ format: 'alphanumeric', target: '#alphanumeric4', previous: '#alphanumeric2' });
$('#alphanumeric4').autotab({ format: 'alphanumeric', target: '#alphanumeric5', previous: '#alphanumeric3' });
$('#alphanumeric5').autotab({ format: 'alphanumeric', previous: '#alphanumeric4' });
<div>
<label>Product Key</label>
<input type="text" id="alphanumeric1" class="alphanumeric" maxlength="5" size="4" /> -
<input type="text" id="alphanumeric2" class="alphanumeric" maxlength="5" size="4" /> -
<input type="text" id="alphanumeric3" class="alphanumeric" maxlength="5" size="4" /> -
<input type="text" id="alphanumeric4" class="alphanumeric" maxlength="5" size="4" /> -
<input type="text" id="alphanumeric5" class="alphanumeric" maxlength="5" size="4" />
</div>
Remove and Restore
Examples
Manually turn off auto tab and filtering functionality on all text boxes.
$('#remove-autotab').on('click', function () {
$('input[type=text]').autotab('remove');
});
<button id="remove-autotab">Turn Off</button>
Manually turn on auto tab and filtering functionality on all text boxes.
$('#restore-autotab').on('click', function () {
$('input[type=text]').autotab('restore');
});
<button id="restore-autotab">Turn On</button>
Filtering
Note: If passing an object, the target and previous fields are ignored, if included, to preserve previously established auto tab rules. Use .autotab(object)
to modify the target and previous fields.
Because of how Autotab's settings are stored, it is possible to define the filter format using data-autotab-format
. If using custom
, place your regular expression in data-autotab-pattern
.
It is possible to specify the filter through an element's class, using the same names that are available when calling the filter. In order to use this feature, $.autotab.selectFilterByClass
must be set to true before initializing Autotab.
Examples
Manually defines text filtering.
$('#salt').autotab('filter', 'text');
<div>
<label>Salt</label>
<input type="text" id="salt" maxlength="16" size="12" />
</div>
Manually defines alphanumeric filtering and converts all alpha characters to uppercase format.
$('.alphanumeric').autotab('filter', { format: 'alphanumeric', uppercase: true });
<div>
<label>Product Key</label>
<input type="text" id="alphanumeric1" class="alphanumeric" maxlength="5" size="4" /> -
<input type="text" id="alphanumeric2" class="alphanumeric" maxlength="5" size="4" /> -
<input type="text" id="alphanumeric3" class="alphanumeric" maxlength="5" size="4" /> -
<input type="text" id="alphanumeric4" class="alphanumeric" maxlength="5" size="4" /> -
<input type="text" id="alphanumeric5" class="alphanumeric" maxlength="5" size="4" />
</div>
Manually defines number filtering via data-autotab-format
. In this example, $(selector).autotab()
will take the attribute into account.
<div>
<label>Phone Number</label>
<input type="text" id="phone1" maxlength="3" size="3" data-autotab-format="number" /> -
<input type="text" id="phone2" maxlength="3" size="3" data-autotab-format="number" /> -
<input type="text" id="phone3" maxlength="4" size="4" data-autotab-format="number" />
</div>
Other random JavaScript examples
$(':input').autotab();
$('#username').autotab({ format: 'alphanumeric', target: '#password' });
$('#password').autotab({ previous: '#username', target: '#confirm' });
$('#product-key').autotab('filter', { format: 'alphanumeric', uppercase: true });
$('#ip-address').autotab('filter', { format: 'custom', pattern: '[^0-9\.]' });
$('#function').autotab('filter', function (text) { alert(text); });
$('#number1, #number2, #number3').autotab('filter', 'number');
$('.ipv6').autotab('filter', 'hexadecimal');
Global Methods
Autotab comes with several global methods, which are probably most useful in edge cases.
Options
var options = {
format: string|function,
pattern: string,
uppercase: boolean,
lowercase: boolean,
nospace: boolean,
maxlength: integer,
target: string|element,
previous: string|element,
trigger: string|array,
tabOnSelect: boolean
};
Filter Formats
Autotab has several filter formats available, all passed into the format
key. If none of the formats meet your needs, Autotab also supports a passing a function or specifying custom
option where you can pass a regular expression.
Known Issues
- Due to security measures placed in iOS, Autotab cannot achieve auto tabbing functionality when hitting a field's character limit. The problem stems from the
focus
event not being triggered manually. As a workaround, Autotab works with iOS by keeping the keyboard open, allowing you to navigate using the arrow shortcuts. - Any script that uses the
keydown
andkeypress
events may conflict with Autotab, or vice versa. As of 1.9.0, Autotab uses event extensions in an attempt to prevent this from happening. - With limitations of
selection
in most text field types, onlytext
,password
andtextarea
fields support auto tabbing and filtering, whiletel
,number
,email
,url
andsearch
support auto tabbing only. Drop
events will not work for IE11 since changing themaxlength
property causes the event from proceeding. IE6-10 work fine, however.
Minify
Autotab uses the Closure Compiler (simple
optimization) to create jquery.autotab.min.js.
Feedback
Please provide feature requests and bug reports here on GitHub.
You can also reach out to me on twitter: @mathachew
Copyright and license
© 2015 Matthew Miller
Licensed under the MIT licensing: http://www.opensource.org/licenses/mit-license.php