Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
akuzemchak edited this page Sep 13, 2010 · 11 revisions

Summary

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.

Basic Usage

No options:

$('#myField').toggleVal();

Default options:

$('#myField').toggleVal({
    focusClass: 'tv-focused',
    changedClass: 'tv-changed',
    populateFrom: 'default',
    text: '',
    removeLabels: false,
    sticky: false
});

Destroy functionality:

$('#myField').toggleVal('destroy');

ToggleVal News

January 15, 2010

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 the alt value, as it should really have never been there. Instead, you can use title, which will populate text from the field’s title="" attribute.
  • Fixed a minor bug with populateFrom: label that caused some wonky results if your field didn’t have an id="" attribute.
  • A field gaining focus that has already been changed will no longer lose the changedClass. The field will have both the changedClass and focusClass.
  • 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!

January 19, 2009

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.

January 7, 2009

ToggleVal 2.0.2 is released. This is a very minor maintenance update that fixes an error when using a compressor such as Packer.

December 15, 2008

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.

September 14, 2008

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.