How to get modelled enumeration Values (value and text) for custom formModelMap - widgetMap.select?

We have an enumeration modelled in sme (Version 8.7.0)

How it looks in the ui:

If error messages exists we want to show a custom select in the ui. For eg (styling is not finished yet):
2023_10_23_custom_formmodelmap

But how can we get the modelled data (value and text) from the enumeration to show in the items select? Is there a selector and what´s the name? Does the selector also includes information about eg label?

Here´s the custom formModelMap code. The items are just hard coded yet.

export function CustomFormModelMap(props: FormModelMap.FormModelComponentProps<FormModel.Control>) {
	const widgetMap = React.useContext(WidgetMapContext);
	const state = props.config.renderOptions.state;
	const errorMessages = !Object.keys(UiStateSelectors.messages()(state)).length;
	const items: SelectItem[] = [{ label: "Mein Profil" }];

	return errorMessages ? (
		<DefaultFormModelMap.Control.component {...props} />
	) : (
		<div style={{ display: "flex", alignItems: "flex-end" }}>
			<widgetMap.Select items={items} />
			<WarningTooltip text="ACHTUNG: Bei einem Profiltypwechsel werden Ihre Änderungen in den Vorschauattributen nicht gespeichert" />
		</div>
	);
}

Thanks for your help :wink:

Hi @michael-thin-timber,
I think reading TPS Investigates: How to use an External Enumeration? would help you with it.

Hey @ahmad-warm-vale,

thanks for your answer and your help. In our case we don´t want to use an externalEnumeration as suggested in TPS Investigates: How to use an External Enumeration?.

Perhaps I was not clear enough in my question :slightly_smiling_face:. We just want to select the “Enumeration Values” by a selector (if one exists :slightly_smiling_face: ) or is there another way to get the data from a modelled enumeration/field etc the code?

For sure we could hard code the profiletypes for the widgetMap.select. For eg:

	const items: SelectItem[] = [{ label: "Mein Profil" }, { label: "Giin-Profil" }, {label: "Crs-Profil"}];

But it doesn´t feel right, if data already exists somewhere :wink:

Maybe there is another solution?

Thanks again for your help :slightly_smiling_face:

We´ve might found some selectors which could help :slightly_smiling_face:

1. ModelSelectors.allDocumentModels


const allDocumentModels = useSelector(ModelSelectors.allDocumentModels());

There we can see deeply nested the Enumeration Values

2. ModelSelectors.modelByName
This selector might suits better but unfortunately it returns undefined!?
We´ve tried “profileType” and “profileDialog” as modelName
const modelByName = useSelector(ModelSelectors.modelByName("profileType"));

How we modelled it in the sme:

Any suggestions what we´ve done wrong?

Thanks

Try to do this.

import { LocalizerContext } from "@com.mgmtp.a12.utils/utils-localization-react/lib/main";
import { EnumerableHelper, EnumerationValue } from "@com.mgmtp.a12.formengine/formengine-core/lib/view";

const localizer = useContext(LocalizerContext).localizer;
const result: EnumerationValue[] = EnumerableHelper.getLocalizedEnumerationValues(
			props.renderConfiguration.renderOptions,
			ModelPath.fromString("/Root/Example/EnumField"),
			localizer
		);

Hey @tin-quantum-aspen,

thanks for your answer and your help! It worked :slightly_smiling_face:

In our version there is no third “localizer: Localizer” parameter.
Bildschirmfoto 2023-10-30 um 10.55.36

Here´s my solution:

export function CustomFormModelMap(props: FormModelMap.FormModelComponentProps<FormModel.Control>) {
const elementPath: ModelPath = props.modelElement.elementPath;
const pathName: string = ModelPath.toString(elementPath);
const result: EnumerationValue[] = EnumerableHelper.getLocalizedEnumerationValues(
		props.config.renderOptions,
		ModelPath.fromString(pathName)
	);

(...)
}

Thanks again :slightly_smiling_face: