K13 DropDownComponent - how to return an int

SOS Childrensvillages asked on February 9, 2023 13:57

I have the following code for a widget property:

[EditingComponent(DropDownComponent.IDENTIFIER, Order = 8, Label = "Image Focus Y axis")]
[EditingComponentProperty(nameof(DropDownProperties.DataSource), "0;top\r\n100;bottom")]
[EditingComponentProperty(nameof(DropDownProperties.DataType), typeof(int))]
[VisibilityCondition(nameof(BackgroundImageUrl), ComparisonTypeEnum.IsNotEmpty)]
public int BgPositionY { get; set; }   
//(Options edited for brevity)

But I get the following error: Message: Configuring property 'DataType' of class 'Kentico.Forms.Web.Mvc.DropDownProperties' with value 'System.Int32' is invalid due to incompatible types.

What do I need to do to get this working and returning an int?

Or alternatively, if it always returns a string, what's the point of the DropDownProperties.DataType?

Correct Answer

Liam Goldfinch answered on February 9, 2023 14:51

Unfortunately I don't think this is possible.

A number of years ago we wanted the same functionality for dropdown components etc, but were told by Kentico Support:

As we understand it, you are trying to build some ultimate universal dropdown component, that will accept all data types. In our experience this could be problematic.

Based on this, I would recommend that you parse the value within the widget's viewcomponent to get the correct integer value (possible using ValidationHelper.GetInteger).

1 votesVote for this answer Unmark Correct answer

Recent Answers

SOS Childrensvillages answered on February 9, 2023 15:01

Thanks Liam. Seems DropDownProperties.DataType is redundant so.

0 votesVote for this answer Mark as a Correct answer

Liam Goldfinch answered on February 9, 2023 15:02 (last edited on February 9, 2023 15:04)

I'm not 100% sure on the DropDownProperties.DataType usage, but I think Kentico uses it a lot internally for the SQL representation. I don't think it is used at all on the form component level itself.

1 votesVote for this answer Mark as a Correct answer

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