Wednesday, August 13, 2008

Show / Hide CRM Form Section

Here is a common requirement that pops up every now and then.


function OnCrmPageLoad()
{
//Hide the Second Section in the first Tab
ToggleSection( 0 , 1 , "none" /* "inline" */);
}

// Tabs and Section Collections are zero based
function ToggleSection( tabIndex , sectionIndex , displayType )
{
var sec = document.getElementById( "tab" + tabIndex );
sec.childNodes[0].rows[ sectionIndex ].style.display = displayType;
}

//Entry Point
OnCrmPageLoad();

8 comments:

Anonymous said...

The section hidden with this techinique does showup when Case is resolved and Case Form is read-only.

Is there any solution to this?

Tag: CRM 4.0, Hide section, readonly, disabled

Adi Katz said...

If you add a simple alert(); does it work?

Anonymous said...

Thanks, I used the following in the "OnLoad" event of the form (form customization in MS CRM 4.0)

# var sec = document.getElementById( "tab" + tabIndex );
# sec.childNodes[0].rows[ sectionIndex ].style.display = displayType;

I replaced tabIndex, sectionIndex & displayType with my values & it worked like a charm :)

Adi Katz said...

Cheers...

Anonymous said...

I used your code to make all fields in a section readonly. Now how do I re-enable them?
//Hide Pricing Fields unless New Pricing
//
ReadOnlyPricing = function (tab, section) {
//Hide the Second Section in the first Tab
ToggleSection(tab, section, "true" /* "inline" */);
}

ToggleSection = function(tabIndex, sectionIndex, displayType) {
var sec = document.getElementById("tab" + tabIndex);
sec.childNodes[0].rows[sectionIndex].disabled = displayType;
}

//Hide Pricing Fields unless New Pricing
//
EnablePricing= function(tab, section) {
//Hide the Second Section in the first Tab
ToggleSection(tab, section, "false" /* "inline" */);
}

Alejandro said...

Adi,

Your code works fine. However, in an IFD environment with SSL (https:// server), when I hide a section, the form pops up a message stating that some of the content is not secured (mixing http and https). The message goes away when I disable the section hiding code. Any ideas?

Alejandro

Alejandro said...

It seems I found the issue. The problem arises if the page has not fully loaded when I execute the code hiding the section.

I attached it to an onchange event - then didn't happen. If I place it in the onload, and runs without waiting till all the window is loaded, it breaks somehow.

Now... I have to find a way to wait till the page is loaded to execute the hide section statement.

Alejandro

Unknown said...

Thanks :))