format state according to isSingleSelect prop in underlying treeselectjs #181
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
stateon the SelectTree, we have to use thedefault()method from theHasStatetrait, which does not accept aClosure.The underlying
treeselectjscomponent expects thevalueprop to be a single value when theisSingleSelectprop istrue, and anarraywhen it isfalse.Since the
multiple()method of theSelectTreedoes acceptClosures, this can lead to situations where the underlying component will throw validation errors (or warnings, rather) in the console when the defaultstatedoes not match the currentisSingleSelectvalue.The underlying component itself applies its own callback
formatState()to thestatebefore validating thevalue, so this change aims to format thestatesuch that no matter whether the defaultstateis 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
stringin 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.