Merge pull request #382 from aaronpowell/tags-input-fixes
tags input fixes
This commit is contained in:
commit
fc0fcdcb7c
4 changed files with 29 additions and 39 deletions
|
|
@ -41,22 +41,22 @@
|
|||
</Flex>
|
||||
</FormItem>
|
||||
<FormItem Label="@LocalizationService.GetString("Engine")">
|
||||
<TagsInput Entities="context.DataSource.Engines" @bind-Values="@context.SelectedOptions.Engines" OptionLabelSelector="e => e.Name" TItem="Engine" />
|
||||
<TagsInput DataSource="context.DataSource.Engines" @bind-Values="@context.SelectedOptions.Engines" OptionLabelSelector="e => e.Name" TItem="Engine" />
|
||||
</FormItem>
|
||||
<FormItem Label="@LocalizationService.GetString("Genre")">
|
||||
<TagsInput Entities="context.DataSource.Genres" @bind-Values="@context.SelectedOptions.Genres" OptionLabelSelector="g => g.Name" TItem="Genre" />
|
||||
<TagsInput DataSource="context.DataSource.Genres" @bind-Values="@context.SelectedOptions.Genres" OptionLabelSelector="g => g.Name" TItem="Genre" />
|
||||
</FormItem>
|
||||
<FormItem Label="@LocalizationService.GetString("Tag")">
|
||||
<TagsInput Entities="context.DataSource.Tags" @bind-Values="@context.SelectedOptions.Tags" OptionLabelSelector="t => t.Name" TItem="Data.Models.Tag" />
|
||||
<TagsInput DataSource="context.DataSource.Tags" @bind-Values="@context.SelectedOptions.Tags" OptionLabelSelector="t => t.Name" TItem="Data.Models.Tag" />
|
||||
</FormItem>
|
||||
<FormItem Label="@LocalizationService.GetString("Platform")">
|
||||
<TagsInput Entities="context.DataSource.Platforms" @bind-Values="@context.SelectedOptions.Platforms" OptionLabelSelector="p => p.Name" TItem="Platform" />
|
||||
<TagsInput DataSource="context.DataSource.Platforms" @bind-Values="@context.SelectedOptions.Platforms" OptionLabelSelector="p => p.Name" TItem="Platform" />
|
||||
</FormItem>
|
||||
<FormItem Label="@LocalizationService.GetString("Developers")">
|
||||
<TagsInput Entities="context.DataSource.Developers" @bind-Values="@context.SelectedOptions.Developers" OptionLabelSelector="c => c.Name" TItem="Company" />
|
||||
<TagsInput DataSource="context.DataSource.Developers" @bind-Values="@context.SelectedOptions.Developers" OptionLabelSelector="c => c.Name" TItem="Company" />
|
||||
</FormItem>
|
||||
<FormItem Label="@LocalizationService.GetString("Publishers")">
|
||||
<TagsInput Entities="context.DataSource.Publishers" @bind-Values="@context.SelectedOptions.Publishers" OptionLabelSelector="c => c.Name" TItem="Company" />
|
||||
<TagsInput DataSource="context.DataSource.Publishers" @bind-Values="@context.SelectedOptions.Publishers" OptionLabelSelector="c => c.Name" TItem="Company" />
|
||||
</FormItem>
|
||||
<FormItem Label="@LocalizationService.GetString("Players")">
|
||||
<InputGroup Compact>
|
||||
|
|
|
|||
|
|
@ -36,25 +36,25 @@
|
|||
</Flex>
|
||||
</FormItem>
|
||||
<FormItem Label="@LocalizationService.GetString("Engine")">
|
||||
<TagsInput Entities="context.DataSource.Engines" @bind-Values="@context.SelectedOptions.Engines" OptionLabelSelector="e => e.Name" TItem="Engine" />
|
||||
<TagsInput DataSource="context.DataSource.Engines" @bind-Values="@context.SelectedOptions.Engines" OptionLabelSelector="e => e.Name" TItem="Engine" />
|
||||
</FormItem>
|
||||
<FormItem Label="@LocalizationService.GetString("Collection")">
|
||||
<TagsInput Entities="context.DataSource.Collections" @bind-Values="@context.SelectedOptions.Collections" OptionLabelSelector="c => c.Name" TItem="Collection" />
|
||||
<TagsInput DataSource="context.DataSource.Collections" @bind-Values="@context.SelectedOptions.Collections" OptionLabelSelector="c => c.Name" TItem="Collection" />
|
||||
</FormItem>
|
||||
<FormItem Label="@LocalizationService.GetString("Genre")">
|
||||
<TagsInput Entities="context.DataSource.Genres" @bind-Values="@context.SelectedOptions.Genres" OptionLabelSelector="g => g.Name" TItem="Genre" />
|
||||
<TagsInput DataSource="context.DataSource.Genres" @bind-Values="@context.SelectedOptions.Genres" OptionLabelSelector="g => g.Name" TItem="Genre" />
|
||||
</FormItem>
|
||||
<FormItem Label="@LocalizationService.GetString("Tag")">
|
||||
<TagsInput Entities="context.DataSource.Tags" @bind-Values="@context.SelectedOptions.Tags" OptionLabelSelector="t => t.Name" TItem="SDK.Models.Tag" />
|
||||
<TagsInput DataSource="context.DataSource.Tags" @bind-Values="@context.SelectedOptions.Tags" OptionLabelSelector="t => t.Name" TItem="SDK.Models.Tag" />
|
||||
</FormItem>
|
||||
<FormItem Label="@LocalizationService.GetString("Platform")">
|
||||
<TagsInput Entities="context.DataSource.Platforms" @bind-Values="@context.SelectedOptions.Platforms" OptionLabelSelector="p => p.Name" TItem="Platform" />
|
||||
<TagsInput DataSource="context.DataSource.Platforms" @bind-Values="@context.SelectedOptions.Platforms" OptionLabelSelector="p => p.Name" TItem="Platform" />
|
||||
</FormItem>
|
||||
<FormItem Label="@LocalizationService.GetString("Developers")">
|
||||
<TagsInput Entities="context.DataSource.Developers" @bind-Values="@context.SelectedOptions.Developers" OptionLabelSelector="c => c.Name" TItem="Company" />
|
||||
<TagsInput DataSource="context.DataSource.Developers" @bind-Values="@context.SelectedOptions.Developers" OptionLabelSelector="c => c.Name" TItem="Company" />
|
||||
</FormItem>
|
||||
<FormItem Label="@LocalizationService.GetString("Publishers")">
|
||||
<TagsInput Entities="context.DataSource.Publishers" @bind-Values="@context.SelectedOptions.Publishers" OptionLabelSelector="c => c.Name" TItem="Company" />
|
||||
<TagsInput DataSource="context.DataSource.Publishers" @bind-Values="@context.SelectedOptions.Publishers" OptionLabelSelector="c => c.Name" TItem="Company" />
|
||||
</FormItem>
|
||||
<FormItem Label="@LocalizationService.GetString("Players")">
|
||||
<InputGroup Compact>
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
OptionLabelSelector="t => t.Name" />
|
||||
|
||||
@code {
|
||||
[Parameter] public BaseDatabaseService<TTaxonomy> DataService { get; set; }
|
||||
[Parameter] public ICollection<TTaxonomy> Values { get; set; }
|
||||
[Parameter] public required BaseDatabaseService<TTaxonomy> DataService { get; set; }
|
||||
[Parameter] public required ICollection<TTaxonomy>? Values { get; set; }
|
||||
[Parameter] public EventCallback<ICollection<TTaxonomy>> ValuesChanged { get; set; }
|
||||
|
||||
ICollection<TTaxonomy> _entities = new List<TTaxonomy>();
|
||||
|
|
@ -21,7 +21,10 @@
|
|||
|
||||
async Task<TTaxonomy> Add(string name)
|
||||
{
|
||||
var taxonomy = Activator.CreateInstance(typeof(TTaxonomy)) as TTaxonomy;
|
||||
var taxonomy = (TTaxonomy?)Activator.CreateInstance(typeof(TTaxonomy));
|
||||
|
||||
if (taxonomy == null)
|
||||
throw new InvalidOperationException($"Could not create instance of type {nameof(TTaxonomy)}");
|
||||
|
||||
taxonomy.Name = name;
|
||||
|
||||
|
|
|
|||
|
|
@ -14,43 +14,30 @@
|
|||
</Select>
|
||||
|
||||
@code {
|
||||
[Parameter] public IEnumerable<TItem>? DataSource { get; set; } = [];
|
||||
[Parameter] public Func<TItem, string>? OptionLabelSelector { get; set; }
|
||||
[Parameter] public required IEnumerable<TItem> DataSource { get; set; }
|
||||
[Parameter] public required Func<TItem, string> OptionLabelSelector { get; set; }
|
||||
|
||||
[Parameter] public Func<string, Task<TItem>>? OnCreateTag { get; set; }
|
||||
|
||||
[Parameter] public ICollection<TItem>? Values { get; set; } = [];
|
||||
[Parameter] public EventCallback<ICollection<TItem>?> ValuesChanged { get; set; }
|
||||
[Parameter] public required ICollection<TItem>? Values { get; set; }
|
||||
[Parameter] public EventCallback<ICollection<TItem>> ValuesChanged { get; set; }
|
||||
|
||||
Dictionary<string, TItem> _items = new();
|
||||
Dictionary<string, TItem> _items = [];
|
||||
IEnumerable<string> _selectedItems = [];
|
||||
|
||||
bool _loading;
|
||||
bool _locked;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
GenerateOptions();
|
||||
}
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
if (Values is null)
|
||||
Values = [];
|
||||
}
|
||||
protected override void OnInitialized() => GenerateOptions();
|
||||
|
||||
void GenerateOptions()
|
||||
{
|
||||
_items = [];
|
||||
_items.Clear();
|
||||
|
||||
if (OptionLabelSelector != null)
|
||||
{
|
||||
if (DataSource != null)
|
||||
foreach (var item in DataSource.DistinctBy(OptionLabelSelector))
|
||||
_items[OptionLabelSelector.Invoke(item)] = item;
|
||||
foreach (var item in DataSource.DistinctBy(OptionLabelSelector))
|
||||
_items[OptionLabelSelector.Invoke(item)] = item;
|
||||
|
||||
_selectedItems = Values?.Select(v => OptionLabelSelector.Invoke(v)) ?? [];
|
||||
}
|
||||
_selectedItems = Values?.Select(v => OptionLabelSelector.Invoke(v)) ?? [];
|
||||
}
|
||||
|
||||
async Task OnValuesChanged(IEnumerable<string> values)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue