Skip to content

Conversation

gp-lnuff
Copy link
Contributor

Currently, to define a default state on the SelectTree, we have to use the default() method from the HasState trait, which does not accept a Closure.
The underlying treeselectjs component expects the value prop to be a single value when the isSingleSelect prop is true, and an array when it is false.
Since the multiple() method of the SelectTree does accept Closures, this can lead to situations where the underlying component will throw validation errors (or warnings, rather) in the console when the default state does not match the current isSingleSelect value.
The underlying component itself applies its own callback formatState() to the state before validating the value, so this change aims to format the state such that no matter whether the default state is a single value or an array, it gets handled such that no warnings are given in the console.

I gave some thought to defining the casting to string in the SelectTree setUp() with formatStateUsing() since at present, if the default value is an array of integers, it will get saved on submit as an array of integers, whereas if the same value is selected by the user or loaded from an existing record, it will get saved as an array of strings - which seems to come from the state casting happening in the underlying component, but since that would break if formatStateUsing() is overridden, I kept it in the underlying formatState() function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant