Problem/Motivation
If a enum with numeric values are mapped with SelectWidget value the component validations failed because the value is a string.
Steps to reproduce
Map a component with following property:
props:
type: object
properties:
heading_level:
title: "Heading level"
$ref: "ui-patterns://enum"
enum:
- 2
- 3
- 4
- 5
- 6
"meta:enum":
2: "h2 (Default)"
3: h3
4: h4
5: h5
6: h6
Proposed resolution
Not sure where to fix that. In the widget or a Proptype adapter?
Issue fork ui_patterns-3473346
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
g4mbiniLooks like a UI Suite DaisyUI yml definiton :)))
A friend told me this same issue on another project (not UI Suite DaisyUI)... But when I tested with UI Suite DaisyUI, I didn't have that problem on my D11 setup ...
I'll ping him @b.khouy !
Comment #3
b.khouy@g4mbini
I encountered the same issue. As a temporary solution, I had to change my enum values to strings (e.g., use '1' instead of 1). In general, it seems that Drupal select widgets always return strings, so the UI Patterns module should account for this. I'll take some time to reproduce the issue and work on it.
Comment #4
pdureau commentedLet's be careful with this one.
So, what can we do in SelectWidget ? a
#processcallback?Comment #5
pdureau commentedMaybe we can leverage SourceInterface::getPropValue()
Proposal:
Comment #6
christian.wiedemann commentedBut we need that for all enums independent of the source. Why not move that logic to an proptype adapter for all enums of type integer
Comment #7
pdureau commentedBecause it is the source which is making a mess here.
What would be the prop type adapter you are thinking about?
Comment #8
christian.wiedemann commentedOr a EnumSourceBase class with getOptions and and we overwrite the getValue method and we do the cast there.
Comment #9
b.khouyI took the time to reproduce this with the latest updates in 2.0.x but couldn't reproduce the issue.
It seems everything is working as expected, so I believe we can close this issue with the status "cannot reproduce"
@christian.wiedemann, you may want to test again with the latest 2.0.x and feel free to reopen in case the problem persists
Comment #10
pdureau commentedThis is surprising, too goof to be to true :)
Let's check again.
Comment #11
pdureau commentedSo, the proposal:
SourceInterface::getPropValue()with the Pierre's proposal in #5EnumSourceBaseas proposed by Christian.SelectWidgetis the only plugin extendingEnumSourceBasefor nowComment #13
christian.wiedemann commentedComment #14
pdureau commentedComment #16
pdureau commentedComment #17
christian.wiedemann commented