Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strong type Value on DataBoundFormComponent<T> #1924

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Radzen.Blazor.Tests/DropDownTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void DropDown_Respects_ItemEqualityComparer()

List<DataItem> boundCollection = [new() { Text = "Item 2" }];

var component = DropDown<string>(ctx, parameters => {
var component = DropDown<List<DataItem>>(ctx, parameters => {
parameters.Add(p => p.ItemComparer, new DataItemComparer());
parameters.Add(p => p.Multiple, true);
parameters.Add(p => p.Value, boundCollection);
Expand Down
10 changes: 5 additions & 5 deletions Radzen.Blazor/DataBoundFormComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,23 @@ public IRadzenForm Form
/// <summary>
/// The value
/// </summary>
object _value;
T _value;
/// <summary>
/// Gets or sets the value.
/// </summary>
/// <value>The value.</value>
[Parameter]
public object Value
public T Value
{
get
{
return _value;
}
set
{
if (_value != value)
if (!Equals(_value, value))
{
_value = object.Equals(value, "null") ? null : value;
_value = object.Equals(value, "null") ? default : value;
}
}
}
Expand Down Expand Up @@ -188,7 +188,7 @@ public virtual IEnumerable Data
if (_data != value)
{
_view = null;
_value = null;
_value = default;
_data = value;
StateHasChanged();
}
Expand Down
10 changes: 5 additions & 5 deletions Radzen.Blazor/RadzenAutoComplete.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ protected override IEnumerable View
/// <param name="args">The <see cref="ChangeEventArgs"/> instance containing the event data.</param>
protected async System.Threading.Tasks.Task OnChange(ChangeEventArgs args)
{
Value = args.Value;
Value = (string)args.Value;

await ValueChanged.InvokeAsync($"{Value}");
if (FieldIdentifier.FieldName != null) { EditContext?.NotifyFieldChanged(FieldIdentifier); }
Expand All @@ -269,11 +269,11 @@ async System.Threading.Tasks.Task SelectItem(object item)
{
if (!string.IsNullOrEmpty(TextProperty))
{
Value = PropertyAccess.GetItemOrValueFromProperty(item, TextProperty);
Value = (string)PropertyAccess.GetItemOrValueFromProperty(item, TextProperty);
}
else
{
Value = item;
Value = (string)item;
}

await ValueChanged.InvokeAsync($"{Value}");
Expand Down Expand Up @@ -344,7 +344,7 @@ public override async Task SetParametersAsync(ParameterView parameters)
{
var item = parameters.GetValueOrDefault<object>(nameof(SelectedItem));
if (item != null)
{
{
await SelectItem(item);
}
}
Expand All @@ -353,7 +353,7 @@ public override async Task SetParametersAsync(ParameterView parameters)

if (parameters.DidParameterChange(nameof(Value), Value))
{
Value = parameters.GetValueOrDefault<object>(nameof(Value));
Value = parameters.GetValueOrDefault<string>(nameof(Value));
}

if (shouldClose && !firstRender)
Expand Down
4 changes: 2 additions & 2 deletions Radzen.Blazor/RadzenDataGridHeaderCell.razor
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@
{
<RadzenProgressBarCircular Style="position:absolute;width:100%;" Visible="@isLoading" Value="100" ShowValue="false" Mode="ProgressBarMode.Indeterminate" />
<RadzenListBox AllowVirtualization="@Column.AllowCheckBoxListVirtualization" AllowClear="true" Multiple="true" Style="height: 300px"
TValue="IEnumerable<object>" [email protected]() Change="@ListBoxChange"
Data=@filterValues Count=@filterValuesCount LoadData="@LoadFilterValues"
TValue="IEnumerable<object>" Value=@((IEnumerable<object>)Column.GetFilterValue()) Change="@ListBoxChange"
Data=@filterValues Count=@filterValuesCount LoadData="@LoadFilterValues"
AllowFiltering="@(!string.IsNullOrEmpty(Column.GetFilterProperty()) && PropertyAccess.GetPropertyType(typeof(TItem), Column.GetFilterProperty()) == typeof(string))"
Disabled="@(!Column.CanSetFilterValue())" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
InputAttributes="@(new Dictionary<string,object>(){ { "aria-label", Column.Title + Grid.FilterValueAriaLabel + Column.GetFilterValue() }})">
Expand Down
Loading