I just created a DotNetDataSource for boolean values (e.g., "true" and "false"). I created a radio button picker with that data source, which worked fine.
However, I then wanted to default to "true" whenever a content editor comes across a new property of that data. I couldn't find a way to do that. It seems that the radio buttons are unset by default and there is no way (via code or configuration) to default them.
Am I missing something? Is there a way to set a default option?
I wouldn't think it should matter, but here's my dot net data source for your reference:
public class ConfigurableBool : IDotNetDataSource
{
[DotNetDataSource(
Title = "Default Value",
Description = @"Enter the value that will be the default (i.e., ""True"" or ""False"").")]
public string DefaultValue { get; set; }
[DotNetDataSource(
Title = "True Label",
Description = @"The label to use for the ""True"" item.")]
public string TrueLabel { get; set; }
[DotNetDataSource(
Title = "False Label",
Description = @"The label to use for the ""False"" item.")]
public string FalseLabel { get; set; }
public IEnumerable<StringPair> GetEditorDataItems(int contextId)
{
var trueLabel = string.IsNullOrWhiteSpace(TrueLabel) ? "True" : TrueLabel;
var falseLabel = string.IsNullOrWhiteSpace(FalseLabel) ? "False" : FalseLabel;
var defaultValue = DefaultValue ?? string.Empty;
var items = new StringPair[]
{
new StringPair(true.ToString(), trueLabel),
new StringPair(false.ToString(), falseLabel)
};
return items
.Select((Item, Index) => new
{
Item,
Index
})
.OrderBy(x => x.Item.Key.InvariantEquals(DefaultValue) ? 0 : 1)
.ThenBy(x => x.Index)
.Select(x => x.Item).ToArray();
}
}
Cool. As mentioned in the ticket, it would be more ideal to be able to dynamically specify the default value (rather than hardcoding it via an attribute).
Setting Default Selection in nuPickers?
I just created a DotNetDataSource for boolean values (e.g., "true" and "false"). I created a radio button picker with that data source, which worked fine.
However, I then wanted to default to "true" whenever a content editor comes across a new property of that data. I couldn't find a way to do that. It seems that the radio buttons are unset by default and there is no way (via code or configuration) to default them.
Am I missing something? Is there a way to set a default option?
I wouldn't think it should matter, but here's my dot net data source for your reference:
Hi Nicholas,
Hadn't considered being able to specify default values, that'd be a good feature to add to the DotNetDataSource attribute: https://github.com/uComponents/nuPickers/issues/124
Thanks, Hendy
Cool. As mentioned in the ticket, it would be more ideal to be able to dynamically specify the default value (rather than hardcoding it via an attribute).
is working on a reply...