0

Environment: Sitecore 9.2, SXA 1.8

I have a droplist field (i.e. FieldABC) that uses a folder as a data source. I want to set the value for this field in the Experience Editor from the ribbon. For that, I have used the Large Gallery Button. I am able to get the data source values but having issues with setting up the MenuItem.Click.

sitecore large gallery button

Objective:

  • Here if the user clicks one of the options, the selected value should be saved in the droplist field of the current item which is being edited in the Experience Editor mode.
  • Also if the droplist field does have any existing value it should be displayed in the chunk instead of the field name (i.e. FieldABC). Suppose if the field contains DS1 as existing value, then the DS1 icon and name should be displayed in the place of FieldABC.

GalleryForm (OnLoad Event):

protected override void OnLoad(EventArgs e)
{
  Assert.ArgumentNotNull(e, nameof(e));
  base.OnLoad(e);
  if (Context.ClientPage.IsEvent)
  {
    return;
  }

  var currentItem = GetCurrentItem();
  if (currentItem == null)
  {
    return;
  }

  var master = Factory.GetDatabase("master");
  var dataSourceFolder = master.GetItem(new Sitecore.Data.ID("{11111111-1111-1111-1111-111111111111}"));
  if (dataSourceFolder != null)
  {
    if (dataSourceFolder.HasChildren)
    {
      foreach (Item child in dataSourceFolder.Children)
      {
        if (!child.Appearance.Hidden || UserOptions.View.ShowHiddenItems)
        {
          var menuItem = new MenuItem();
          this.FieldABC.Controls.Add(menuItem);
          menuItem.Header = child.DisplayName;
          menuItem.Icon = child.Appearance.Icon;
          menuItem.Click = string.Format("item:load(id={0},language={1},version={2})", child.ID, child.Language, child.Version.Number);
          // How to set the field value using menuItem.Click?
        }
      }
    }
  }
}

How to achieve this functionality? Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.