Search code examples
sitecoresitecore6sitecore7

Sitecore - Adding button to FormDialog


Is it possible to add a custom button to a Sitecore FormDialog other than OkButton and CancelButton e.g. instead of this

<FormDialog Icon="cool.png" Header="A really cool header" Text="Link or un-link items" OKButton="Link" CancelButton="Close">

but something more like this

<FormDialog Icon="cool.png" Header="A really cool header" Text="Link or un-link items" OKButton="Link" UnLinkButton="UnLink" CancelButton="Close">

Solution

  • I don't think it is possible to add another button by passing in an attribute on the FormDialog element without modifying original the FormDialog.xml

    But there is a placeholder element defined in the DialogForm control (in /sitecore/shell/Controls/Dialogs)

    <def:Placeholder name="Buttons"/>
    

    In the xml for your custom application you add controls to this placeholder:

    <control xmlns:def="Definition" xmlns="http://schemas.sitecore.net/Visual-Studio-Intellisense">
      <MyCustomForm>
        <FormDialog Icon="cool.png" Header="A really cool header" Text="Link or un-link items" OKButton="Close" CancelButton="false">
    
          <CodeBeside Type="MyCustomCode.Dialogs.MyCustomForm, MyCustomCode"/>
    
          <GridPanel Columns="2" CellPadding="4" Width="100%" Height="100%">
              <!-- Panel code here -->
          </GridPanel>
    
          <Border def:placeholder="Buttons" runat="server" style="float:right;">
            <Button Header="Link" runat="server" Type="button" Click="Link_Click" />
            <Button Header="Unlink" runat="server" Type="button" Click="Unlink_Click" onclick="return confirm('Are you sure you want to unlink?');" />      
          </Border>
    
        </FormDialog>
      </MyCustomForm>
    </control>
    

    Note you want to pass in CancelButton="false" which hides the cancel button and set the OK button text to "Close". Handle your Link/Unlink button server actions in the code behind. I've styled the button group to float:right so they then site next to the Close button.

    Form with custom buttons