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);
            }
        });
    }
}
Advertisements

One Reply to “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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s