Closed himdel closed 5 years ago
@miq-bot add_reviewer @eclarizio
Ok, @eclarizio if you can (re)review, I think this should be ready, and the description matches the current state.
(I'd still like to write some tests, just to make sure the behaviour is also tested with weird values, not only the strictly valid ones)
Thanks :) Fixed a couple more tests which were failing because of the 0 thing.
And maybe I'll leave the other tests for a separate PR so that we can merge & build.
Yeah that seems fine to me. Nice 👍
Hammer backport details:
$ git log -1
commit 2fbdd510fd60cba955839abad2265804a8627f18
Author: Harpreet Kataria <hkataria@redhat.com>
Date: Fri Jul 12 14:32:00 2019 -0400
Merge pull request #402 from himdel/integer-single-bz1729046
DialogUser - convert single-select default_value to the right data_type
(cherry picked from commit 8b48923eeee45c72ced0d34807f747ce98c1ff2f)
https://bugzilla.redhat.com/show_bug.cgi?id=1729594
Introduced in https://github.com/ManageIQ/ui-components/pull/394, we now require
default_value
's type to match the types of keys invalues
.But:
default_value
- we have to do the conversion to the right type. For multiselects, the value is JSON-encoded and preserves types, but for single select, even integer values get passed as strings.values
to the right typeSo now, all of these get converted (on load) to the type in
data_type
:default_value
for single-selectsdefault_value
for multi-selectsvalue[0]
fromvalues
for all selectsThe conversion rules are as follow:
data_type
isstring
:null
orundefined
(actual nil values, not strings) get treated special and stay asnull
toString()
data_type
isinteger
:null
orundefined
(actual nil values, not strings) get treated special and stay asnull
1
), or trailing non-numeric parts (23 kg
), but excluding base-specific notations (0x123
) or scientific notation (2e3
)A side effect of this change is that
0
gets treated as a valid default dropdown option, so a first option with 0 value will now always get sorted first, whereas previously, this treatment would only apply to non-numeric or null.Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1729046