---
title: Validated Choices
---

A set of choices with one active choice. Lists and sets can be automatically converted to choices with their `toChoices()` method. 

`ValidatedChoice` is validation of the type the choices are, so the `get()` and `apply()` methods will return and consume choices in the relevant type directly.

<CodeTabs>

```java !!tabs Java
// Defines a set of weights the user can choose from. Note the use of ValidatedSets toChoices()
public ValidatedChoice<Integer> validatedWeightChoices = ValidatedSet.ofInt(1, 2, 5, 10, 20).toChoices(ValidatedChoice.WidgetType.CYCLING); //Validated choice has optional GUI and translation controls too.
```

```kotlin !!tabs Kotlin
// Defines a set of weights the user can choose from. Note the use of ValidatedSets toChoices()
var validatedWeightChoices = ValidatedSet.ofInt(1, 2, 5, 10, 20).toChoices(ValidatedChoice.WidgetType.CYCLING) //Validated choice has optional GUI and translation controls too.
```

</CodeTabs>

### Translation Providers
The choices provided may not be automatically [`Translatable`](../Translation), like numbers or strings. To provide translations and tooltips for your choices, ValidatedChoice accepts a translationProvider and descriptionProvider; BiFunctions that convert the choice into a translated text and hovered tooltip.

The weight choices from the example above might display like `"Ultra Rare", "Very Rare", "Rare", "Uncommon", "Common"` instead of `1, 2, 5, 10, 20`, with hovered tooltips that explain what each rarity value means.

<CodeTabs>

```java !!tabs Java
// Defines a set of weights the user can choose from. Note the use of ValidatedSets toChoices()
public ValidatedChoice<Integer> validatedWeightChoices = ValidatedSet.ofInt(1, 2, 5, 10, 20).toChoices(
    ValidatedChoice.WidgetType.CYCLING,
    ValidatedChoice.translate(),  //ValidatedChoice has a helper method that produces an automatic translated text based on a pre-defined key format.
    ValidatedChoice.translate("desc")   //see the documentation for details on the key format.
); 
```

```kotlin !!tabs Kotlin
// now we build out a translation and description provider. 
var validatedWeightChoices = ValidatedSet.ofInt(1, 2, 5, 10, 20).toChoices(
    ValidatedChoice.WidgetType.CYCLING,
    ValidatedChoice.translate(),  //ValidatedChoice has a helper method that produces an automatic translated text based on a pre-defined key format.
    ValidatedChoice.translate("desc")   //see the documentation for details on the key format.
)
```

</CodeTabs>

<Callout>
See the documentation page <a target="_blank" rel="noopener" href="https://fzzyhmstrs.github.io/fconfig/-fzzy%20-config/me.fzzyhmstrs.fzzy_config.validation.misc/-validated-choice/index.html">here 🗗</a>
</Callout>