format state according to isSingleSelect prop in underlying treeselectjs #181
+8
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, to define a default
state
on the SelectTree, we have to use thedefault()
method from theHasState
trait, which does not accept aClosure
.The underlying
treeselectjs
component expects thevalue
prop to be a single value when theisSingleSelect
prop istrue
, and anarray
when it isfalse
.Since the
multiple()
method of theSelectTree
does acceptClosure
s, this can lead to situations where the underlying component will throw validation errors (or warnings, rather) in the console when the defaultstate
does not match the currentisSingleSelect
value.The underlying component itself applies its own callback
formatState()
to thestate
before validating thevalue
, so this change aims to format thestate
such that no matter whether the defaultstate
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 SelectTreesetUp()
withformatStateUsing()
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 ifformatStateUsing()
is overridden, I kept it in the underlyingformatState()
function.