The Problem
We had a requirement in Sitecore where content authors should not be able to uncheck publishing targets in the Publish dialog.
Sometimes, content authors accidentally uncheck the publishing target and then report that publishing is not working. We wanted to avoid this situation by ensuring that the publishing target always remains selected.
One option we considered was to deny Read access to the publishing target using Sitecore security. However, our setup had only one publishing target. After denying Read access, the entire
Publish button in the Experience Editor ribbon became disabled.
This was not the expected behaviour. We wanted to restrict changes to the publishing target selection without affecting the publishing functionality.
There are two possible approaches worth considering.
Option 1: Hide the Publishing Targets
The first approach is to keep all publishing targets selected and hide the target checklist from the dialog.
The customization is in the following file:
/sitecore/shell/client/Applications/Publishing/PublishingShared.js
Locate the
setDefaultCheckboxes logic and replace the existing target-locking behaviour with a helper like the following:
var selectAndHideTargets = function () {
if (!this.CheckBoxListTargets) {
return;
}
// Keep all targets selected
if (typeof this.CheckBoxListTargets.checkAll === "function") {
this.CheckBoxListTargets.checkAll();
}
// Hide the target checklist
this.CheckBoxListTargets.IsVisible = false;
// Fallback if IsVisible does not hide the rendering
$(this.CheckBoxListTargets.el).hide();
}.bind(this);
Next, update the target-loading block so that the checklist is hidden after the target data has loaded:
this.GenericDataSourceTargets.loadData({
onSuccess: function () {
selectAndHideTargets();
if (this.CheckBoxListTargets &&
this.CheckBoxListTargets.off) {
this.CheckBoxListTargets.off(
"change:Items",
selectAndHideTargets,
this
);
}
if (this.CheckBoxListTargets &&
this.CheckBoxListTargets.on) {
this.CheckBoxListTargets.on(
"change:Items",
selectAndHideTargets,
this
);
}
}.bind(this)
});
This approach selects all publishing targets and hides the checklist so that content authors cannot uncheck them through the dialog.
Important: Sitecore Support provided this as sample code. It was not officially tested by the support team.
Hiding a control is not the same as disabling it. Validate that the approach works as expected in your Sitecore version.
Option 2: Keep the Targets Visible but Disable the Checkboxes
Another possible approach is to keep the publishing targets visible but prevent authors from changing their selection.
An AI-assisted response suggested modifying
PublishingShared.js to select all targets and disable the checkbox inputs.
Add the following helper immediately after the existing cookie preferences declaration:
var cookiePreferences = Preferences.LoadCookie();
var lockAllTargets = function() {
if (!this.CheckBoxListTargets) return;
if (typeof this.CheckBoxListTargets.checkAll === "function") {
this.CheckBoxListTargets.checkAll();
}
var $root = $(this.CheckBoxListTargets.el);
var $inputs = $root.find('input[type="checkbox"]');
$inputs.each(function() {
this.disabled = true;
this.setAttribute('aria-disabled', 'true');
this.setAttribute('tabindex', '-1');
});
$root.addClass('sc-disabled');
}.bind(this);
Then update the target-loading block:
this.GenericDataSourceTargets.loadData({
onSuccess: function() {
lockAllTargets();
if (this.CheckBoxListTargets &&
this.CheckBoxListTargets.off) {
this.CheckBoxListTargets.off(
"change:Items",
lockAllTargets,
this
);
}
if (this.CheckBoxListTargets &&
this.CheckBoxListTargets.on) {
this.CheckBoxListTargets.on(
"change:Items",
lockAllTargets,
this
);
}
}.bind(this)
});
If the existing code calls
this.CheckBoxListTargets.checkAll() separately in the same dialog flow, review that call as well and replace it with the new locking logic where appropriate.
The intention is to keep the targets selected while making the checkboxes non-editable.
However, this is an
AI-suggested customization, not a verified Sitecore solution. Directly disabling HTML inputs may not cover every way the SPEAK component can update its selection. The
sc-disabled class also does not, by itself, guarantee that the component is disabled.
Test this approach carefully before using it in production.
We raised this with Sitecore Support to understand whether this was the right way to achieve this and if there were any other recommended ways.
Sitecore Support Response
Sitecore Support registered a feature request for this requirement under reference number
PDXP-33658. The request can be tracked for consideration in a future product release.
The support team also shared a similar sample customization for hiding the publishing targets option in the Publish dialog.
Things to Consider Before Implementing
Before deploying either customization, I would recommend the following:
- Back up the original
PublishingShared.js file.
- Test the publishing dialog from both Content Editor and Experience Editor.
- Confirm that all required publishing targets remain selected.
- Verify that the Publish button stays enabled and publishing completes successfully.
- Test whether the customization affects other publishing scenarios or dialogs.
- Document the customization because Sitecore upgrades may overwrite changes to client files.
Conclusion
The requirement is simple: content authors should be able to publish content without accidentally disabling the only publishing target.
Sitecore Support registered this as feature request
PDXP-33658 and shared a sample customization to hide the publishing target checklist. An alternative is to keep the checklist visible while disabling its checkboxes, but that approach needs additional validation.
For either solution, test the behaviour in your specific Sitecore version before deploying it. A client-side customization should not inadvertently disable publishing or create a false impression that publishing targets are locked.
Hope this helps!
Comments
Post a Comment