-
Notifications
You must be signed in to change notification settings - Fork 1
Home
ToggleVal gives you the option to populate the default text of form fields (in a few different ways), and will then toggle the default value when the field receives and loses keyboard focus.
$('#myField').toggleVal();
$('#myField').toggleVal({
focusClass: 'tv-focused',
changedClass: 'tv-changed',
populateFrom: 'default',
text: '',
removeLabels: false,
sticky: false
});
$('#myField').toggleVal('destroy');
Wow, almost one year since the last big update. Today, ToggleVal 3.0 is officially released, and there is some cool stuff. Here we go!
- You can now access and modify the default options with
$.fn.toggleVal.defaults
, if you so choose. - For the
populateFrom
option, you can no longer use thealt
value, as it should really have never been there. Instead, you can usetitle
, which will populate text from the field’stitle=""
attribute. - Fixed a minor bug with
populateFrom: label
that caused some wonky results if your field didn’t have anid=""
attribute. - A field gaining focus that has already been changed will no longer lose the
changedClass
. The field will have both thechangedClass
andfocusClass
. - There are now two brand new pseudo selectors that you can use —
:toggleval
, which will return all elements with the ToggleVal events bound to them, and:changed
which returns ToggleVal items that have been changed from their default values. - There’s a new option, called
sticky
, which if true will prevent the default text from re-populating once the field loses focus.
Also, the other big news is that Github is the new official home of ToggleVal (and my other plugins), so feel free to fork them if you like!
ToggleVal 2.1 is released. This release adds a couple new features, including the ability to specify default text directly from the toggleVal()
function (using populateFrom: 'custom'
and the new text
option), and includes a new destroy method that removes ToggleVal functionality from an element. Also, 2.1 uses the data attribute for all comparison logic, which proves to be much more reliable. Version 2.1 is fully compatible with jQuery 1.3.
ToggleVal 2.0.2 is released. This is a very minor maintenance update that fixes an error when using a compressor such as Packer.
ToggleVal 2.0.1 is released. This minor update adds a jQuery data attribute of defText to each field affected by ToggleVal. This attribute stores the default text of the field, which can be utilized to compare fields to previous states.
ToggleVal version 2.0 goes public today. The entire plugin has been rewritten, so if you are currently using it please pay extra close attention to the documentation, as your old scripts may break.