I have created a custom action button that appears on the DisplayForm for a specific content type.
On the list view I would also like to enable the button but only when the specific content type is selected and only if there is only one item selected.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Description="Button Blah"
Title="Button Title"
Id="{53801DF2-A778-4E93-8191-ACBC06C7D4DD}"
Location="???????????????"
RegistrationType="ContentType"
RegistrationId="0x010014D754C688D12A4FB4C811B4B4F67A5C"
Sequence="0"
Rights="ViewListItems"
xmlns="http://schemas.microsoft.com/sharepoint/">
<CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Define the (UI) button to be used for this custom action -->
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.ListForm.Display.Manage.Controls._children">
<Button Id="{10C2173C-537F-4D3D-8394-9ADB8486CEBE}"
Command="{99AAAD72-4AB6-4EC0-8B5A-E3F194145A4D}"
Image32by32="~site/_layouts/Images/GCMS/SomeImage32.png"
Image16by16="~site/_layouts/Images/GCMS/SomeImage16.png"
Sequence="0"
LabelText="Button Label Text"
Description="Button Blah"
TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<!-- Define the action expected on the button click -->
<CommandUIHandler Command="{99AAAD72-4AB6-4EC0-8B5A-E3F194145A4D}" CommandAction="~site/_layouts/custompage.aspx?List={ListId}&ID={ItemId}" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
</Elements>
I have tried the following in the CommandUIHandler:
<CommandUIHandler
Command="MYSOLUTION.CreateActionCommand"
EnabledScript="javascript:SP.ListOperation.Selection.getSelectedItems().length = 1;"
CommandAction="javascript: alert('My Command!');" />
</CommandUIHandlers>
but that enables the button constantly.
If I use the following:
<CommandUIHandler
Command="MYSOLUTION.CreateActionCommand"
EnabledScript="javascript:SP.ListOperation.Selection.getSelectedItems().length > 0;"
CommandAction="javascript: alert('My Command!');" />
</CommandUIHandlers>
It works when I select one item or more.
But my requirement is to only enable the button when ONLY one item is selected - not multiple selected items.
How do I enable/disable a button when a specific content type is selected in a list view?