Replies: 12 comments 3 replies
-
Hi @bjarnef, thanks for raising this. According to the Microsoft docs, the default value of an Enum is
This means that it will either use whichever enum member is set to If you have control over the Enum, then a workaround would be to set whichever you'd like the default to have a value of Update: Found a StackOverflow answer with further explanation: https://stackoverflow.com/a/4967673/12787 I have thought about ways to set a default value, but it started to get complex with the disconnect between the data source and list editor. Needs more thought and prototyping. 😃 |
Beta Was this translation helpful? Give feedback.
-
@leekelleher yeah, I know. However I think in some cases if might make sense to have a default option in the UI, while keeping the default enum values - especially if using the enum in configuration of multiple data type instances. E.g. a WeekDay or .NET Furthermore if used in Checkbox List it would be might be useful to make Monday - Friday selected by default, while Saturday and Sunday are unselected. |
Beta Was this translation helpful? Give feedback.
-
@bjarnef, thank you - I do like the idea of setting a default value, (whether this is for Enum data source or any other), but I struggle with where (conceptually) the user would configure that? e.g. is it the responsibility of the data source? or the list editor? (but then I'd designed the list editor to be agnostic of data source) I could argue that this could be done using Content Templates (blueprints), but then BlockList/NestedContent doesn't support those, (although Contentment's Content Blocks does). Or a last resort (as a developer), programmatically set a default value using a I guess this comes down to whether we need a solution for a specific problem, or it's a more conceptual question, should Data List be able to define a default value? Hopefully, I'm not sounding like I'm trying to shut down any discussions... I'm totally happy to hear any proposed ideas. 🙏 |
Beta Was this translation helpful? Give feedback.
-
@leekelleher I imagine this is something to configurate in the list editor (or maybe overwrite the value from data source). With a enum data source and a checkbox list, I guess it isn't possible to set multiple default checked values? In a specific use-case I am using enum data source + radiobutton list for some block lidt configuration settings. Text Position Text Width With checkbox list I can imagine use-cases where it would be useful to set multiple default values (maybe common used values or something which should be enabled 90% of the times, so it is just easier to uncheck the other 10% of the times). |
Beta Was this translation helpful? Give feedback.
-
Ran into this issue today as well, when using drop down list in my case the first option been default was fine however the dropdown was not pre populated so I had to add some code using I think the control of default value should sit with the editor, this would allow the data source to be reused with different default values based on its use case. This would also allow the checkbox list to have multiple selected, as its in control. |
Beta Was this translation helpful? Give feedback.
-
I'm not convinced that the List Editor is the appropriate place to configure a default value - since it knows nothing about the data source, (and making it aware of the data source would introduce much complexity). Potential idea could be to make use of the proposed Preview panel, see PR #53. Which would display a rendering of the configured Data List editor. But I'm not 100% on this, conceptually in Umbraco we do not (generally) define default values at Data Type level - which is why Content Templates exist. (I'm aware this isn't ideal for sub-content editors, a la BlockList, NC, DTGE, et al) 🤔 |
Beta Was this translation helpful? Give feedback.
-
I can see you're point about defaults and content templates. Maybe it's more of a documentation task to highlight setting a default value using code? (by linking out to our or a more complex example) Not sure if you could set a default value by data type definition easily using |
Beta Was this translation helpful? Give feedback.
-
Quick thought about an default value for the Enum specifically... I wonder if the object-type should be Nullable Enum instead? 🤔 |
Beta Was this translation helpful? Give feedback.
-
If allow empty or generally? |
Beta Was this translation helpful? Give feedback.
-
General, (as the Data Source knows nothing about the List Editor's config). It could be configurable at the Enum Data Source level... but then I start to feel it's death by config options, which is what I nearly fell into with issue #42 (many granular options vs. a single sensible one) |
Beta Was this translation helpful? Give feedback.
-
Moved this topic to a discussion. I'm still unsure how to best approach a "default value" feature for Data List. |
Beta Was this translation helpful? Give feedback.
-
Just came here after searching for how to set a default value :) I'd made DataList with User-defined list of "Smaller", "Normal" & "Bigger" as the Data source, and the Buttons List editor - my rendering code treats no value/null/empty and "Normal" as the same - but I'd of course like to have the "Normal" button pressed as default too. I actually thought I could do it in the Preview as mentioned earlier, and when that didn't seem to work, I had a look at the JSON to see if maybe there was a secret "default" key available 😁 I can see why it's tricky, having swappable sources and editors though... 🤔 |
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem? Please describe.
The Data List configuration using .NET Enumeration works great for e.g. Text Size and Text Position in settings of a Block List editor block. However by default in use the first enum value as default value even though no value has been selected in the list editor.
Describe the solution you'd like
It would be great if we could configurate e.g Checkbox List, Dropdown List or Radio Button List selecting one or more default options.
Beta Was this translation helpful? Give feedback.
All reactions