EliJDonahue
11/2/2016 - 11:41 PM

[ArasLabs/custom-form-css] Show contents of custom_icon form field

[ArasLabs/custom-form-css] Show contents of custom_icon form field

<img id="myIcon" name="myIcon" src="../customer/svg/package.svg" vspace="20" hspace="20" />

<script>
  chooseIcon = function()
  {
    var icn = "../customer/svg/";
    
    // get classification, gets "none" if getProperty returns null 
    var thisItem = document.thisItem;
    var classification = thisItem.getProperty("classification","none");
    
    // get icon fields
    var defIcon = document.getElementById("large_icon_img");
    var myIcon = document.getElementById("myIcon");
    
    // choose file name
    switch (classification)
    {
      case "none":
        // choose part icon file
        icn = defIcon.getAttribute("src");
        break;

      case "Assembly":
        icn += "package.svg";
        break;

      case "Component":
        icn += "circuit-board.svg";
        break;

      case "Material":
        icn += "beaker.svg";
        break;

      case "Software":
        icn += "file-binary.svg";
        break;
    }
    
    // style custom icon
    myIcon.setAttribute("src",icn);
    myIcon.style.visibility = "visible";
    myIcon.style.display = "block";
    
    // hide default icon element
    defIcon.style.visibility = "hidden";
  }

  // choose icon onLoad
  window.addEventListener("load", chooseIcon);
</script>