jimbo
jimbo

Reputation: 1018

Resetting formcheck for mootools on checkbox change

I have a form that uses formcheck (a MooTools class that allows you to perform checks on validation) everything works fine, I have also built a part of the form that can be hidden, (by using mootools' 'slide' class) on a checkbox selection.

The problem is that the fields that are hidden are linked into the formcheck class, and are registered when the page loads via:

<script type="text/javascript">
//<![CDATA[
window.addEvent('domready', function() {

var myCheck = new FormCheck('form1');

I have tried clearing the class on the fields when the checkbox is checked via:

$('auto').addEvent('click', function(e){
        if (document.getElementById("auto").checked == true) {
            myVerticalSlide.slideOut();
            document.getElementById("password").setAttribute("class", "");

but because it is registered at the start this doesn't have any effect, my next logial step was to recall the:

var myCheck = new FormCheck('form1');

But this then created two formchecks...

So the solution i need is to either reset the formcheck, or clear the password field from it. I hope this explains the problem, any question help welcome :)

Upvotes: 1

Views: 986

Answers (1)

LHMathies
LHMathies

Reputation: 2434

The FormCheck documentation is quite sparing, but looking in the source code I see the functions register and dispose.

You don't need to remove the class from the input element, dispose will just clear its actions from the list in the FormCheck object, and register will parse the class again and add the actions:

$('auto').addEvent('click', function(e){
        if (document.getElementById("auto").checked == true) {
            myVerticalSlide.slideOut()
            myCheck.dispose($('password'))
        }
        else {
            myVerticalSlide.slideIn()
            myCheck.register($('password'))
        }
    })

Upvotes: 2

Related Questions