Results 1 to 2 of 2

Thread: Need help with conditional spry

  1. #1
    Junior Member Newbie
    Join Date
    May 2012
    Location
    Charlotte, NC
    Posts
    2

    Default Need help with conditional spry

    Hi All,

    I am creating a form where certain fields are hidden based on the selections made in certain other fields. These dynamically hidden fields have spry validation on them. My problem is that the validation on these dynamically hidden fields is preventing submission even if the fields are hidden. I have some code that I am trying to dynamically enable/disable the spry validation for these fields (as they are shown/hidden) but I can't seem to get it working.

    Thanks in advance for any help.

    Kind regards,

    Ken

    Code:
      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";
          //enable spry field validation for these fields
          sprytextfield2 = new Spry.Widget.ValidationTextField("spryEquipID", "none", {validateOn:["blur"]});
          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";
          //destroy spry field validation for these fields
          sprytextfield2.resetClasses();
          sprytextfield2.destroy();
          sprytextfield2 = null;
    
          spryselect1.resetClasses();
          spryselect1.destroy();
          spryselect1 = null;
          
    		} else {
    			// hide the div
    			document.getElementById("Equipment").style.display = "none";
    			document.getElementById("Satellites").style.display = "none";
          //destroy spry field validation for these fields
          sprytextfield2.resetClasses();
          sprytextfield2.destroy();
          sprytextfield2 = null;
    
          spryselect1.resetClasses();
          spryselect1.destroy();
          spryselect1 = null;
        }
    };

  2. #2
    Junior Member Newbie
    Join Date
    May 2012
    Location
    Charlotte, NC
    Posts
    2

    Default SOLVED: Need help with conditional spry

    Nevermind. Got it sorted.

    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;
          } 
     
        }  
    };

Bookmarks

Posting Permissions

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