Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle selects (etc) with numeric keys #4688

Merged
merged 1 commit into from
Nov 9, 2021
Merged

Conversation

jasonvarga
Copy link
Member

@jasonvarga jasonvarga commented Nov 9, 2021

When select fields (or radio/checkboxes/button_group fields) use numeric options, like this...

myfield:
  field:
    type: select
    options:
      1: One
      2: Two

...the fieldtype ends up saving the value as a string (javascript objects can't have numeric keys), so you end up with this:

myfield: '1'

Then in #4483, it was made so that if the value didn't match an option exactly, it would use itself as the value and label.
The string version of the number does not exactly equal the option in this case.

This PR makes it so that integer strings get treated as integers.

ie. both these work

myfield: '1'
myfield: 1

Floats get treated as strings though, since you can't have a float as a key in PHP. They'll be strings, even if there's a real float in the data.

myfield:
  field:
    type: select
    options:
      1.5: One point five  # technically '1.5'
      2.5: Two point five  # and '2.5'

ie. both these work:

myfield: '2.5'
myfield: 2.5

Fixes #4574

@jasonvarga jasonvarga merged commit e5bd278 into 3.2 Nov 9, 2021
@jasonvarga jasonvarga deleted the fix/4574-select-label branch November 9, 2021 17:37
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.

4483 broke select_var:label
1 participant