Disable Required Fileds When Hide Tabs in CRM 2011

There are requirements to hide tabs according to the selections in the form and if any tab contains required fields it will display them automatically and asking user to fill those fields when saving the form.

Following Javascript function will disalbe all the controls in the tab and then it will not ask user to fill those required fields.

// tabName : Name of the Tab, isDisable: booloean value for Enable/Disable controls
DisableAllControlsInTab: function (tabName, isDisable) {
    var tabControl = Xrm.Page.ui.tabs.get(tabName);
    if (tabControl != null) {
        Xrm.Page.ui.controls.forEach(
        function (control, index) {
            if (control.getParent().getParent() == tabControl && control.getControlType() != "subgrid") {
                control.setDisabled(isDisable);
            }
        });
    }
}

Following Javascript function can be used to show or hide the tab and it will disable/enable its controls accordingly.

// tabName : Name of the Tab, isVisible: booloean value for visibility of the Tab
ShowHideTabEnableDisableAllControls: function (tabName, isVisible) {
    // Show or Hide the tab
    Xrm.Page.ui.tabs.get(tabName).setVisible(isVisible);
    var tabControl = Xrm.Page.ui.tabs.get(tabName);
    if (tabControl != null) {
        Xrm.Page.ui.controls.forEach(
        function (control, index) {
            if (control.getParent().getParent() == tabControl && control.getControlType() != "subgrid") {
                // If the tab is visible=false, controls will be disabled=true
                control.setDisabled(!isVisible);
            }
        });
    }
}
Advertisement

Author: Indika Abayarathne

MSc in IT [University of Colombo] Solutions Architect | Consultant Technologies: Power Platform | Dynamics CE | Azure

One thought on “Disable Required Fileds When Hide Tabs in CRM 2011”

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: