Overview

FancyForm is a powerful checkbox replacement script used to provide the ultimate flexibility in changing the appearance and function of HTML form elements. It's easy to use and degrades gracefully on all older, non-supporting browsers.

At a glance


Example

Checkboxes

Radio buttons


Full-featured demo

For a working demo, including onSelect / onDeselect events, animation effects, and more, see the FancyForm demo page.


How to Use

Easy Install

  1. Add the following anywhere in your website:
    <script type="text/javascript" src="js/mootools.1.11.js"></script>
    <script type="text/javascript" src="js/moocheck.js"></script>
  2. Add CSS styles on your website to specify the appearance of the checkboxes and radio buttons. Add styles for the classes checked and unchecked for checked / unchecked checkboxes respectively, and likewise use the classes selected and unselected for radio buttons that are checked / unchecked.

Expecting more steps? Sorry to disappoint ;)


Advanced Styling

Note: The FancyForm.start() function is called at the bottom of fancyform.js inside a window.addEvent block. If you're using the techniques described in this section, make sure you replace this call, or add the options to it.

Upgrading Mootools

FancyForm uses the ultra-lightweight Mootools JavaScript framework. Mootools 1.11 is included in the download for FancyForm with Window.DomReady, Element.Selectors and their dependencies. You may want to download Mootools for yourself if you plan to use more of it's features in your website.

Limiting fancification

If you don't want to apply styling to every checkbox and radio button on your page, pass in an array containing the elements you want to style as the first argument for FancyForm.start() near the bottom of fancyform.js. For example,

var chkBoxes = new Array();
chkBoxes[0] = document.getElementById('fancy-box');
chkBoxes[1] = document.getElementById('other-fancy-box');
FancyForm.start(chkBoxes);

Since Mootools is being used, you can also use the $$ function and specify CSS selectors, such as:

FancyForm.start( $$('#content .fancy-form input') );

Leave this parameter or pass in `0` if you want the script to target all applicable checkboxes and radio buttons.

Change classes

The second argument for the FancyForm.start() function, if set, should be an object or array containing any extra options.

If you want to change the classes used by FancyForm, you can set the options onClasses and offClasses.

The following configuration is used as default if nothing is specified:

FancyForm.start( 0, {
    onClasses: {
        checkbox: 'checked',
           radio: 'selected'
        },
    offClasses: {
        checkbox: 'unchecked',
           radio: 'unselected'
        }
} );

If a type of input (checkbox or radio) is omitted from onClasses, elements of that type wont be affect by the script at all.

In this example, selected checkboxes will have the class `f_checked` and radio button wont be styled by the script (as they're omitted).

var f_onClasses = {
	checkbox: 'f_checked'
}
var f_offClasses = {
    checkbox: 'f_unchecked'
}
FancyForm.start( 0, {
    onClasses: f_onClasses,
    offClasses: f_offClasses
} );

The above is equivalent to:

FancyForm.start( 0, {
    onClasses: ['f_checked'].associate(['checkbox']),
    offClasses: ['f_unchecked'].associate(['checkbox'])
} );

Extra classes

To make advanced styling easier, you can specify five extra classes to use. These go in with the second argument under extraClasses:

For example, the following will apply a class 'fancy' to all elements targeted by FancyForm:

FancyForm.start( 0, {
    extraClasses: {
        all: 'fancy'
    }
});

Use `1` or `true` to apply all the default extra classes, which is equivalent to using:

// setting extraClasses: 1 is the same as using...
FancyForm.start( 0, {
    extraClasses: {
        checkbox: 'f_checkbox',
        radio: 'f_radio',
        on: 'f_on',
        off: 'f_off',
        all: 'fancy'
    }
});

Javascript hooks

If you'd like to execute a javascript function each time a button is checked, use the property onSelect in the options. For example, the following will display an alert with the name of the selected checkbox upon clicking:

FancyForm.start( 0, {
	onSelect: function(chk){
		alert(chk.getProperty('name'));
	}
});

You can also execute code when a checkbox or radio button is deselect by using onDeselect. Here, the animateCheckbox function is called:

FancyForm.start( 0, {
	onDeselect: animateCheckbox
});

function animateCheckbox(chk){
	console.log(chk.getProperty('name')+' deselected');
	doSomeOtherThing(chk);
	fadeOut(chk);
}

Support

I don't see any difference before and after adding the script.

Firstly, make sure you've actually applied some styles for the FancyForm classes (see How to use).

If you have any other JavaScript on your site, check if you're getting any Javascript errors. If there is an error, it may give you an indication about where the conflict is occurring.

How much does this script cost?

The script itself is free. You may use it in any way you wish, as long as proper attribution is provided. A link to my site would be appreciated.

Got another question? I'm all ears.


Contact

Feedback on this script, whether it's criticism or accolades, is greatly appreciated. Support questions may also be asked for now.

Please visit http://lipidity.com/contact-me/ to contact me.