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); } }); } }
Reblogged this on Shahzad Sarang gloB's.