Custom Table with radio button field.

Danuta Welz asked on March 11, 2016 16:32

My question is about custom table with a "radio button" field. This field name is Keyword and it has a "list of options": type1;Name1 type1;Name2 type1;Name3

I don't know how to get value (Name1, Name2 ...) from a transformation. I use {% Keyword %} there but it gives text (type1, type2 or type3).

What should I use instead.

Correct Answer

Trevor Fayas answered on March 11, 2016 16:39

The Display name is purely for display, the only value saved is the Value (not the display name).

So if you want to get the Display Name, you'll have to do some custom logic.

A: A very manual and lengthy but quick, put some logic that {% if (val == "type1") { return "Name1";}|(identity)GlobalAdministrator%}, etc

B: A more manual but less lengthy approach, is create some form of mapping to reference that you can go from the value back to the display name. (macro to send "type1", look up the mapping (like a custom table), and return the value.

C: Best but slightly harder, is use the ClassInfoProvider to grab your Custom Table's class definition, and parse the XML to find this field's list of value;display names, then parse it to find the proper display name for the given value and set that logic in a macro. This will then always be 'up to date' and if you add the Custom Table's Class Name, Field Name to the macro's method, you can reuse it for other items.

Hope these help!

0 votesVote for this answer Unmark Correct answer

Recent Answers


Roman Hutnyk answered on March 11, 2016 16:50 (last edited on March 11, 2016 16:50)

All Trevor's ideas are good. Personally I would choose option B. But there is one more: instead of specifying key/value for list options, specify just values

Name1

Name2

...

This will store actual names in database, so no extra efforts are required. Downside of this approach is that you'll mess up your data if you update names in the list options.

1 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on March 11, 2016 16:55 (last edited on March 11, 2016 16:55)

Option B may have more advantages as well, if you make a separate custom table that has the Name-Value data, you can...

1: Make your radio button fields based off of a SQL query of that table

2: Use the custom Table to find the Name off of the value. You may be able to get the value without a custom macro as well, since i think Kentico allows you to query Custom Tables through the macro engine.

0 votesVote for this answer Mark as a Correct answer

Danuta Welz answered on March 11, 2016 17:12

Thanks for answers. They helped me to resolve my problem. Regards

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.