locked
Show/hide Form sections RRS feed

  • Question

  • This is driving me nuts.  It works in preview for Update and Create forms.  After being published it only works on Create forms:

    //Show or hide logic based on cost type selection
    switch(costType2)
    {
    case '1':
      sec.childNodes[0].rows[1].style.display = "inline";
      sec.childNodes[0].rows[2].style.display = "none";
      break;
    case '2':
      sec.childNodes[0].rows[2].style.display = "inline";  
      sec.childNodes[0].rows[1].style.display = "none";
      break;
    }

     

    Wednesday, May 19, 2010 6:41 PM

Answers

  • I solved it. 

    I had a slightly different method running on the form Load event:

    crmForm.all.new_invoicedcosts_c.parentElement.parentElement.parentElement.style.display='inline';
    crmForm.all.new_involvementtype_c.parentElement.parentElement.parentElement.style.display='none';

    This worked ok with

    sec.childNodes[0].rows[1].style.display = "inline"; 
    sec.childNodes[0].rows[2].style.display = "none";

    apart from in the circumstance noted above

    I changed the form Load event to use

    sec.childNodes[0].rows[1].style.display = "inline"; 
    sec.childNodes[0].rows[2].style.display = "none";

    and all is now welll

    Thank you for your help

     

     

    • Marked as answer by adyscaife Wednesday, May 19, 2010 8:49 PM
    Wednesday, May 19, 2010 8:49 PM

All replies

  • Hi.

    Could you paste full code you use here? You use costType2 variable but it is not declared...


    Truth is opened the prepared mind

    My blog (english)
    Мой блог (русскоязычный)
    Wednesday, May 19, 2010 6:55 PM
    Moderator
  • Yes is costType2 neither 1 or 2 on the Update form possibly?

    Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/
    Wednesday, May 19, 2010 6:59 PM
  • It is a picklist

     

    var costType2 = crmForm.all.new_costtype.DataValue;

    //Show or hide logic based on cost type selection
    switch(costType2)
    {
    case '1':
      sec.childNodes[0].rows[1].style.display = "inline";
      sec.childNodes[0].rows[2].style.display = "none";
      break;
    case '2':
      sec.childNodes[0].rows[2].style.display = "inline";  
      sec.childNodes[0].rows[1].style.display = "none";
      break;
    }

    Wednesday, May 19, 2010 7:02 PM
  • put the following line at the top and enable IE-> Tools > I.Options -> untick disable script debugging (i.e. enable script debugging)

    debugger;

     

    Now with this you can go step by step and find out the cuase of this issue.

    hope this helps..

     

    Wednesday, May 19, 2010 7:06 PM
  • Maybe you are already aware, but it's worth mentioning, costType2 could be null, in which case none of the switch paths will be executed. 
    Daniel Cai | http://danielcai.blogspot.com
    Wednesday, May 19, 2010 7:17 PM
  • I am testing the validity of values 1 or 2.  A null value is intended not to execute a change in the sections. 

    Wednesday, May 19, 2010 7:54 PM
  • That's really odd. I am using similar code as yours, never had any problem. 

    You should try MayankP's advice, and use debugger; statement to help you figure out the problem. 

    I am suspecting that another line of code throw an error before reaching your switch code. 


    Daniel Cai | http://danielcai.blogspot.com
    Wednesday, May 19, 2010 8:08 PM
  • I have removed all other Javascript from the field OnChange event to test that.  I get the same result with only the lines of code posted above.  I don't believe there is any syntactical error.  As I said I also note it operates correctly in preview.  It also operates correctly after publication for a form on Create. 

    The only circumstance in which it does not work is when an existing record is edited and the picklist value is changed.    It must be something idiosyncratic. 

    Wednesday, May 19, 2010 8:19 PM
  • OK, there is the problem. Did you actually hook up the picklist's onchange event?

    You may do something like this: 

    function CostType_OnChange() {
      var costType2 = crmForm.all.new_costtype.DataValue;
    
      //Show or hide logic based on cost type selection
      switch(costType2)
      {
      case '1':
       sec.childNodes[0].rows[1].style.display = "inline"; 
       sec.childNodes[0].rows[2].style.display = "none"; 
       break;
      case '2':
       sec.childNodes[0].rows[2].style.display = "inline";  
       sec.childNodes[0].rows[1].style.display = "none"; 
       break;
      }
    }
    
    CostType_OnChange();
    crmForm.all.new_costtype.attachEvent('onchange', CostType_OnChange);
    
    


    Daniel Cai | http://danielcai.blogspot.com
    Wednesday, May 19, 2010 8:25 PM
  • I did as you suggested and moved the code to the form load and hooking the On Change event for the field.  Same result.
    Wednesday, May 19, 2010 8:34 PM
  • I solved it. 

    I had a slightly different method running on the form Load event:

    crmForm.all.new_invoicedcosts_c.parentElement.parentElement.parentElement.style.display='inline';
    crmForm.all.new_involvementtype_c.parentElement.parentElement.parentElement.style.display='none';

    This worked ok with

    sec.childNodes[0].rows[1].style.display = "inline"; 
    sec.childNodes[0].rows[2].style.display = "none";

    apart from in the circumstance noted above

    I changed the form Load event to use

    sec.childNodes[0].rows[1].style.display = "inline"; 
    sec.childNodes[0].rows[2].style.display = "none";

    and all is now welll

    Thank you for your help

     

     

    • Marked as answer by adyscaife Wednesday, May 19, 2010 8:49 PM
    Wednesday, May 19, 2010 8:49 PM