Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder MaDmiX's Avatar
    Join Date
    Feb 2012
    Location
    Charlotte, NC
    Posts
    190
    Thanks
    50
    Thanked 0 Times in 0 Posts

    Setting and unsetting variables

    Hi All,

    I would like to enable / disable my field validation based upon the status of a given checkbox in my form but I am unsure about how to "unset" the varibles that control the validation. If the user clicks the checkbox, this displays the fields ant enables my validation just fine. But if the user then unckeck the box, the field is hidden but the validation remains enabled and the form cannot be submitted. Here is my code:

    Code:
    if (document.getElementById("OnAirVariance").checked) {
    var sprytextfield3 = new Spry.Widget.ValidationTextField("spryStartTime", "time", {validateOn:["blur"], format:"HH:mm:ss", useCharacterMasking:true});
    var sprytextfield4 = new Spry.Widget.ValidationTextField("spryEndTime", "time", {format:"HH:mm:ss", useCharacterMasking:true, validateOn:["blur"]});
    var sprytextfield5 = new Spry.Widget.ValidationTextField("spryMaterialID", "none", {validateOn:["blur"]});
    var sprytextfield6 = new Spry.Widget.ValidationTextField("spryTitle", "none", {validateOn:["blur"]});
    }else{
    I NEED TO BE ABLE TO REVERSE THE SET VARIABLES SO THE VALIDATION WILL NOT STAY IN EFFCT
    }
    Thanks in advance for any help.

    Kind regards,

    Ken

  • #2
    Regular Coder MaDmiX's Avatar
    Join Date
    Feb 2012
    Location
    Charlotte, NC
    Posts
    190
    Thanks
    50
    Thanked 0 Times in 0 Posts
    Nevermind. Got it sorted. If anyone is interested, this may be helpful:

    Code:
    function preparePage() {
    	
      document.getElementById("List1").onclick = function() {
    		if (document.getElementById("List1").value=="Equipment issue") {
    			// use CSS style to show it
    			document.getElementById("Equipment").style.display = "block";
    			document.getElementById("Satellites").style.display = "none";
    
          // if there isn't a validaton, build one
          if(!sprytextfield2){
          sprytextfield2 = new Spry.Widget.ValidationTextField("spryEquipID", "none", {validateOn:["blur"]});
          }
          if(!spryselect1){
          spryselect1 = new Spry.Widget.ValidationSelect("spryEquipLoc", {validateOn:["blur"]});
          } 
    
    		} else if (document.getElementById("List1").value=="Satellite issue") {
    			// use CSS style to show it
    			document.getElementById("Satellites").style.display = "block";
    			document.getElementById("Equipment").style.display = "none";
    
          //clear any values from these fields
          document.getElementById("EquipLoc").value=null
          document.getElementById("EquipID").value=null
          
          //if exists, destroy spry field validation for these fields
          if (sprytextfield2) {
          sprytextfield2.resetClasses();
          sprytextfield2.destroy();
          sprytextfield2 = null;
          }
    
          if (spryselect1) {
          spryselect1.resetClasses();
          spryselect1.destroy();
          spryselect1 = null;
          } 
        
    		} else {
    			// hide the div
    			document.getElementById("Equipment").style.display = "none";
    			document.getElementById("Satellites").style.display = "none";
    
          //clear any values from these fields
          document.getElementById("EquipLoc").value=null
          document.getElementById("EquipID").value=null
          
          //if exists, destroy spry field validation for these fields
          if (sprytextfield2) {
          sprytextfield2.resetClasses();
          sprytextfield2.destroy();
          sprytextfield2 = null;
          }
    
          if (spryselect1) {
          spryselect1.resetClasses();
          spryselect1.destroy();
          spryselect1 = null;
          } 
     
        }  
    };
    Kind regards,

    Ken


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •