How to Retrieve Enumeration Caption in a Custom Widget

0
I’m currently working on a CustomWidget and need to retrieve the Caption value of an enumeration. As you know, the Name of an enumeration entry serves as its key, and the universe attribute in the enumeration actually maps to this Name. However, I’d like to display or use the user-friendly Caption instead. Could you please advise how I can access the corresponding Caption for an enumeration value within the CustomWidget?
asked
3 answers
0

Hi Man

 

My Bad inside a Mendix Custom Widget, you cannot directly read the caption of an enumeration entry at runtime.Mendix does NOT expose enumeration captions to JavaScript after mendix 9+, But I can give somework around which is easy by manually map Enumeration Values to Captions (Hardcoded in Widget).

Step 1 — Create a static map inside widget source.

Step 2 — Get current name of enumeration from EditableValue

const current = props.enumAttribute.value; // "New" / "Approved" / "Rejected" 
const caption = StatusEnumMap[current];

This works only if captions don’t need localization and rarely change.

 

I had tested this is working as expected but the only problem is it is harcoded.But instead of hardcode you can use json also.

 

If it doesnt help let me know I can help you out!!

answered
0

Hi,

I am working on a solution to use the full power of enumerations. Code is ready but I still have to write documentation. It is part of my Mendix collection called ConventCommons.

You can have a sneak preview on https://github.com/LuchKlooster/ConventCommons.

I hope you can figure out how to implement it. It's pretty self explaining.

answered
0

Sorry Su Tong,

Forgot to set the repro to public.

I added a shorthand implementation guide in github readme.

 

To everybody: You can have a sneak preview on https://github.com/LuchKlooster/ConventCommons.

answered