During development, I did prototype with a Buttons editor (and a "Templated List" editor, where you could add custom HTML), but they were a little too experimental for the initial v1.0 release. I'm hoping to include them in a future release.
public Dictionary<string, object> DefaultValues => default;
Do you have any examples of how to set a default value?
EDIT---
Ahh.. that is for config default values.. ;) What I was looking for was a way to set a initial default value from the list... guess i can put in a textfield in the config and just type the value.. ;)
Could you share how you managed to set the default value?
I'm trying to set the default value using an enum, but it's not working. Any idea what I'm doing wrong?
public class HeroBlockVariantsDataSource : IDataListSource
{
public Dictionary<string, object> DefaultValues => new Dictionary<string, object>() { { HeroBlockVariants.Large.ToString(), HeroBlockVariants.Large.ToString() } };
public IEnumerable<ConfigurationField> Fields => Enumerable.Empty<ConfigurationField>();
public string Group => string.Empty;
public OverlaySize OverlaySize => OverlaySize.Medium;
public string Name => "Hero Block Variants";
public string Description => "Data source for all hero block variants.";
public string Icon => "icon-tags";
public IEnumerable<DataListItem> GetItems(Dictionary<string, object> config)
{
var blockVariants = Enum.GetValues(typeof(HeroBlockVariants)).Cast<HeroBlockVariants>();
if (blockVariants?.Any() == true)
{
return blockVariants.Select(x => new DataListItem
{
Name = x.ToString(),
Value = x.ToString()
});
}
return Enumerable.Empty<DataListItem>();
}
}
In the context of the IDataListSource class, the DefaultValues are for the configuration Fields of that data-source, not the value of the property (on a content node) itself.
The need for a default value for the Data List itself has come up in discussion a few times. See the thread on package's GitHub repo:
Ultimately it comes around to "how would you set a default value for any property-editor?" Which is either using Content Templates (blueprints) or custom C# code to hook into the Editor Model API, (either EditorModelEventManager.SendingContentModel for v8, or SendingContentNotification for v9).
Custom list editor
Hi Lee,
This package is super nice.. :D .. I'm pretty sure that I will use this in every upcomming project.. ;)
A really nice feature would be the posibility to add your own list editor..
So you could build something like this or other editors.. ;)
/ulrich
Hi Ulrich, thanks for the nice feedback!
You can definitely create your own custom list editors, here's some initial documentation. (It probably needs to be expanded out to its own page).
https://github.com/leekelleher/umbraco-contentment/blob/develop/docs/editors/data-list.md#extending-with-your-own-custom-list-editor
Here's an example of how the CheckboxList one is built...
During development, I did prototype with a Buttons editor (and a "Templated List" editor, where you could add custom HTML), but they were a little too experimental for the initial v1.0 release. I'm hoping to include them in a future release.
Cheers,
- Lee
Oh.. very sweet... :D
..better tell my wife it is going to be late tonight.. ;)
/ulrich
I hope your wife is forgiving. ;-)
She is.. ;) .. and this is really, really cool... :D
Great work.. ! :D
Hi Lee,
I'm a bit curious about this:
Do you have any examples of how to set a default value?
EDIT---
Ahh.. that is for config default values.. ;) What I was looking for was a way to set a initial default value from the list... guess i can put in a textfield in the config and just type the value.. ;)
/ulrich
Hi Ulrich, yeah you're correct, those are the default values for the config.
Setting the default value for the property can be done as you said. 👍
Hi Lee,
This is really cool.. ;) .. the sky is the limit.. :D
/ulrich
Hey Ulrich,
Could you share how you managed to set the default value?
I'm trying to set the default value using an enum, but it's not working. Any idea what I'm doing wrong?
Hi Sven,
In the context of the
IDataListSource
class, theDefaultValues
are for the configurationFields
of that data-source, not the value of the property (on a content node) itself.The need for a default value for the Data List itself has come up in discussion a few times. See the thread on package's GitHub repo:
https://github.com/leekelleher/umbraco-contentment/discussions/91
Ultimately it comes around to "how would you set a default value for any property-editor?" Which is either using Content Templates (blueprints) or custom C# code to hook into the Editor Model API, (either
EditorModelEventManager.SendingContentModel
for v8, orSendingContentNotification
for v9).I hope this helps?
Cheers,
- Lee
Awesome! 🎉 #h5yr
is working on a reply...