sween_sp
sween_sp

Reputation: 113

Access List Options for a Field in a Custom Table in Kentico 10

I have a custom table with a few fields that have list options for the user to select from when adding the content. Is there something in the API that allows me to access the options for a particular field so I can use those same options in a filtering widget? List Example

Something like the below but that works for fields in a custom table?

var guids = ParentDocument.GetValue("CustomFieldName").Split(';');
var referencedDocs = DocumentHelper.GetDocuments().WhereIn("DocumentGuid", guids);

UPDATE - The code in case the link in the answer changes:

  protected string[] GetFormFieldOptions()
    {
        DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo("custom.MyPageTypeName");
        if (dci != null)
        {
            //Get the data from the form field
            FormInfo fi = new FormInfo(dci.ClassFormDefinition);
            FormFieldInfo ffi = fi.GetFormField("Industry");
            string[] industries = ffi.Settings["Options"].ToString().Split('\n'); 
            return industries;
        }
        return null;
    }

Upvotes: 1

Views: 504

Answers (2)

Roman Hutnyk
Roman Hutnyk

Reputation: 1549

Use DataClassInfoProvider in order to get data you need. Check this blog post to see more details.

Upvotes: 1

Brenden Kehren
Brenden Kehren

Reputation: 6117

You can use the same code as you have in your question. The difference is you need to get 2 different things which are not available at the "Page" or "Document" level:

  1. Custom table object
  2. Custom table item based on #1

You use the API to get the custom table item:

var cti = CustomTableItemProvider.GetItem(<id or guid>, "yourcustom.tableclassname);
if (cti != null)
{
    string[] s = ValidationHelper.GetString(cti.GetValue("YourField"), "").Split(";");
}

Update
To get a dynamic list of options in a field you can simply use a listing control like a dropdown list or a radio button list as your control (vs. a textbox). Then in the properties for the dropdownlist, you can set it to a query. In the query enter something like

-- if you wan to have a 'select one' add this
SELECT '', '-- select one --'
UNION
SELECT ItemID, FieldName
FROM CustomTable_Name
ORDER BY 2

Upvotes: 0

Related Questions