Home > CRM 2011, JScript > Disabling controls in a section using JScript

Disabling controls in a section using JScript

We can’t disable a Section using “setDisabled(false)”, as Section is a container of controls.

Below is the logic to disable all the controls in a section

  • Loop through all the page controls
  • If the control’s parent is the specified section, disable the control

Below are the functions to disable controls in a Section. We need to pass “Section” object as parameter

function disableSectionFields(section) {

if (section) {

Xrm.Page.ui.controls.forEach(function (control, index) {

if (control && doesControlHaveAttribute(control)) {

if (control.getParent() === section) {

control.setDisabled(true);

}

}

});

}

}

// Validate if the control is not  IFrame/webresource/subgrid as we can’t disable them

function doesControlHaveAttribute(control) {

var controlType = control.getControlType();

return controlType != “iframe” && controlType != “webresource” && controlType != “subgrid”;

}

// Get the Section object by Tab name & Section name

function getSection(tabName, sectionName) {

var tab = Xrm.Page.ui.tabs.get(tabName);

if (tab) {

return tab.sections.get(sectionName);

}

return null;

}

How do I call

  • Assume my tab name is “tab_name” & section name is “section_name”
  • Get the section object and pass to the “disableSectionFields” function as below

var mySection = getSection(“tab_name”, “section_name”);

if (mySection) {

disableSectionFields(mySection);

}

🙂

Advertisement
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: