2

We have a custom FormDialog (standard combination of xml and cs file that inherits DialogForm) that appears when a custom button in the Content Editor ribbon is clicked. Using some user input, the form creates an item relating to the current selected context item, but does not affect the item directly.

We have a content editor warning that appears on the the context item when it has one of these associated items created for it, but we're finding that the warning doesn't appear until after the user manually clicks on the item again, effectively "reloading" the item. We want the content editor to automatically "refresh" AKA reload the item, ideally as part of the FormDialog's required "OnOk" method (inherited from the DialogForm class) or something that makes sense for when the form's server side functionality is performed.

All suggestions we've seen so far have pointed to the following command:

string load = $"item:load(id={item.ID},language={item.Language},version={item.Version})";

With the following implementation:

Context.ClientPage.ClientResponse.Timer(load, 0 )

However, we're seeing nothing occur when using this code, implemented just before calling base.OnOk(sender, args). The command clearly gets passed in, according to breakpoints set in Sitecore's related .js file, but the desired action doesn't seem to be happening.

Are we approaching this wrong? Are we seeking something inherently not intended to be support through DialogForms?

1
  • Can you please share your code for the command and the OnOk method? Commented Nov 15, 2020 at 21:28

1 Answer 1

0

From what I have tested, the command item:load should work but it should be implemented at the proper location. So, as you mentioned you are triggering the dialog from a custom button on the Ribbon, it means that you have create a command and a piece of code similar to the below

public class CustomModal : Command
{
    public override void Execute(CommandContext context)
    {
        Sitecore.Context.ClientPage.Start(this, "Run", context.Parameters);
    }

    protected static void Run(ClientPipelineArgs args)
    {
        if (!args.IsPostBack)
        {
            UrlString urlString = new UrlString(UIUtil.GetUri("control:CustomUrl"));
            SheerResponse.ShowModalDialog(urlString.ToString(), "800", "300", "", true);
            args.WaitForPostBack();
        }
        else
        {
            // PROCESS RESULT
        }
    }
}

Instead of executing the item:load in the OnOk method of the DialogForm, you need to trigger it in the command implementation. Below is the code snippet I've used to test and it works

public class CustomModal : Command
{
    public override void Execute(CommandContext context)
    {
        Sitecore.Context.ClientPage.Start(this, "Run", context.Parameters);
    }

    protected static void Run(ClientPipelineArgs args)
    {
        if (!args.IsPostBack)
        {
            // Triggers to open the dialog
            UrlString urlString = new UrlString(UIUtil.GetUri("control:CustomUrl"));
            SheerResponse.ShowModalDialog(urlString.ToString(), "800", "300", "", true);
            args.WaitForPostBack();
        }
        else
        {
            // Process the result and reload here
            string load = "item:load(id={110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9},language=en,version=1)";
            Context.ClientPage.ClientResponse.Timer(load, 0);
        }
    }
}
2
  • This works perfectly! Thank you Hishaam! One small note, you mentioned "item:refresh" in your comment but showed item:load in your code (same as my mentioned command). I can confirm item:load works to this purpose. I am unsure if item:refresh was a typo, I believe that command's purpose is to refresh the item's tree (AKA children). I also had to add a "return" statement within my IsPostBack conditional block, or else the corresponding dialog would not close. Commented Nov 25, 2020 at 14:46
  • Hey, yeah it is a typo mistake. I have updated the answer Commented Nov 25, 2020 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.