javascriptspry

How can I remove Spry Validation from a Radio Group?


I understand how to destroy validation for a text field, but when I apply the same logic to a radio button group, the Spry Validation doesn't destroy.

In the following example, you see the radio button and where I'm trying to destroy the validation if the the user chooses anything other than Individual.

<script>
var spryradio1;

function checkData(){
    // get the value
    document.getElementById("spryradio1").style.display = "none";
    var value = document.applicationform.type.options[document.applicationform.type.options.selectedIndex].value;
    if(value !=""){
    if(value == "Individual"){

        if(!spryradio1){
        spryradio1 = new Spry.Widget.ValidationRadio("spryradio1");
        }

        document.getElementById("spryradio1").style.display = "block";

    } else {


        // if there is a validaiton in sprytextfield destory it, and clear the variable

        if(spryradio1 && spryradio1.destroy){
            spryradio1.resetClasses();
            spryradio1.destroy();
            spryradio1 = null;
            }

        document.getElementById("spryradio1").style.display = "none";
    }
    // proceed with the rest as normal
    }
    return true;
};
</script>

Solution

  • The radio buttons didn't like the resetClasses line; the SpryValidation was destroyed when I changed the lines to:

    if(spryradio1)
    { spryradio1.reset();
    spryradio1.destroy();
    spryradio1 = null; }