locked
Enabling a Field on a Disabled Tab RRS feed

  • Question

  • I have code that disables all the fields on the tab but I am having troubles enabling a single field on the disabled tab. The below code searches if the Person is under 40 and if it is, all of the tabs on the entity are disabled. My custom field new_customfield is what needs to be enabled. I thought the last line in the code that is bolded would enable the field but it does not seem to work. Does anyone have any ideas?

    Here is my code:

    function disableTab(tabIndex)
    {
     var tab = document.all["tab" + tabIndex];

        for (var i = 0; i < tab.all.length; i++)
        {
            if (tab.all[i].Disabled !== undefined)
            {
                tab.all[i].Disabled = true;
            }
        }
    }

    if (crmForm.all.new_customfield.DataValue <40)
    {
     alert("Person is under 40!");
     disableTab(0);
     disableTab(1);
     disableTab(2);
     crmForm.all.new_customfield.disabled=false;
    }

     

    Wednesday, December 22, 2010 9:10 PM

Answers

  • Sorry, my mistake, I didn't read your code properly, I found where the bug is in your code, it's a simple typo

    The .disabled = false, should be Disabled (capital D)

    function disableTab(tabIndex)
    {
     var tab = document.all["tab" + tabIndex];

        for (var i = 0; i < tab.all.length; i++)
        {
            if (tab.all[i].Disabled !== undefined)
            {
                tab.all[i].Disabled = true;
            }
        }
    }

    if (crmForm.all.new_customfield.DataValue <40)
    {
     alert("Person is under 40!");
     disableTab(0);
     disableTab(1);
     disableTab(2);
     crmForm.all.new_customfield.Disabled=false;
    }


    Kids don't try this at home!
    • Proposed as answer by Aaron1968 Thursday, December 23, 2010 2:04 AM
    • Marked as answer by mkarls Thursday, December 23, 2010 3:40 PM
    Wednesday, December 22, 2010 10:59 PM

All replies

  • Hi

    The reason is you're disabling via the DOM but enabling via CRM properties. If you have a look at the dom via IE Dev Toolbar you'll see that for each attribute there are number of html elements, eg: <attribute_c> and <attribute_d>, so make sure you enable the same dom elements per attribute.

    Hope that makes sense
    Kids don't try this at home!
    Wednesday, December 22, 2010 9:16 PM
  • I added the following lines:

    crmForm.all.new_customfield_c.disabled=false;
     crmForm.all.new_customfield_d.disabled=false;

    And I still cannot get the field to be enabled. I checked out the source code and only saw _c and _d elements.

     

    Wednesday, December 22, 2010 9:22 PM
  • Hi

    If you take a closer look you'll see that _d is the table column not the input control itself, you're disable function needs to be a bit smarter about which elements it disables, eg: only elements with id ending with _d


    Kids don't try this at home!
    Wednesday, December 22, 2010 9:32 PM
  • I'm not too sure that I follow....

    I am having no troubles disabling the tabs (that disable all of the fields on the tabs), what I am having trouble with is enabling just one field on a tab that is disabled.

     

    Wednesday, December 22, 2010 10:49 PM
  • Sorry, my mistake, I didn't read your code properly, I found where the bug is in your code, it's a simple typo

    The .disabled = false, should be Disabled (capital D)

    function disableTab(tabIndex)
    {
     var tab = document.all["tab" + tabIndex];

        for (var i = 0; i < tab.all.length; i++)
        {
            if (tab.all[i].Disabled !== undefined)
            {
                tab.all[i].Disabled = true;
            }
        }
    }

    if (crmForm.all.new_customfield.DataValue <40)
    {
     alert("Person is under 40!");
     disableTab(0);
     disableTab(1);
     disableTab(2);
     crmForm.all.new_customfield.Disabled=false;
    }


    Kids don't try this at home!
    • Proposed as answer by Aaron1968 Thursday, December 23, 2010 2:04 AM
    • Marked as answer by mkarls Thursday, December 23, 2010 3:40 PM
    Wednesday, December 22, 2010 10:59 PM
  • Ahhh so stupid! Thank you Gayan!

    Thursday, December 23, 2010 3:41 PM