2

I am currently intergrating Episerver with an API.

Its pretty simple, I post a form from my Episerver website, and the form data gets sent to the API and is processed by some other system.

I have already made a hardcoded HTML form and got the form posting to my API with no problems. - So I have got that bit to work.

Now what I need to do, is create managment functiality for the form it self.....

Requirements

A user can create a form. One of the fields in the form needs to have a drop downlist with a dyamic list of values (configured in episerver). The rest of the fields that appear on the form (just strings) are determined by what the user selects from the drop downlist.

(there is a fixed list of fields that could be on the form) I need to store this list somewhere in episerver.

I need for someone to be able to log on to episerver, create a new "API Form Block" enter a list of items for the drop downlist, and then for each item in that list, select from a fixed number of form fields to be assosiatited with that drop down list item.

I appriciate that there are many parts to this question, and I understand I will need to write some front end code to show/hide the correct fields based on the dropdown selection, im not asking for advice about how to do any of that.

The main thing I want suggestions on, is what features of episerver can help me to store the data structure Required, I have started looking at the PopertyList but not to sure if this is the correct approach, how could I assosiate a row in a Propertylist with Sevral rows in another PropertyList?

This is my first EPI server project, so I'm hoping there might be something I don't know about in episerver which will make this task easy.

Ideas please........?

UPDATE:

I have started trying to implement this using a Property List. I know how to create a basic property list, but is it possible to have a selection of check boxes in a property list? Something like this:

enter image description here

Ayo Adesina
  • 2,231
  • 3
  • 37
  • 71
  • 2
    Have looked at the `SelectMany` attribute in combination with a `SelectionFactory`? – Ted Nyberg Apr 19 '18 at 06:45
  • When it comes to storing structures like that the DDS (Dynamic Data Store) isn't a bad choice but will need to write your own gui to manage it, I'd recommend creating a widget for that. Combining that with a selectionFactory as suggested by @TedNyberg isn't a bad choice https://world.episerver.com/documentation/developer-guides/CMS/dynamic-data-store/ – Eric Herlitz Apr 19 '18 at 12:13
  • Thanks for the suggestions guys, because the fields I need are actually a fixed set of fields I have just hard coded them, but as soon as i get this all working, I'll come back and try your suggestions out to make this dynamic – Ayo Adesina Apr 19 '18 at 14:25

1 Answers1

1

How did you get on?

I'd suggest combining a PropertyList with a SelectionFactory and use the SelectMany attribute.

We had a requirement where we needed to allow our Episerver user to select multiple Months, so we created a SelectionFactory as below;

using System.Collections.Generic;
using System.Globalization;
using EPiServer.Shell.ObjectEditing;

namespace Episerver.WebApp.Business
{
    public class MonthSelectionFactory : ISelectionFactory
    {
        public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
        {
            var result = new List<ISelectItem>();
                        
            foreach (var monthName in DateTimeFormatInfo.CurrentInfo.MonthNames)
            {
                if (string.IsNullOrWhiteSpace(monthName))
                    continue;

                result.Add(new SelectItem()
                {
                    Text = monthName,
                    Value = monthName.ToLower()
                });
            }

            return result;
        }
    }
}

You can do any number of things in your SelectionFactory class to get a dynamic list of items rather than returning a hardcoded list. Eg. You could use Episerver API to get a ContentLoader to get the Items from a Page or Block, or get data from DDS (Dynamic Data Store).

Then your Page / Block (in your case in your PropertyList) add the SelectMany Attribute to your Property.

 [SelectMany(SelectionFactoryType = typeof(Business.MonthSelectionFactory))]
 public virtual string AvailableMonths { get; set; }

Your PropertyList property will store a comma delimited list of the selected values. Which you should be able to handle in your Controller or View.

Darren S
  • 920
  • 5
  • 15