Skip to content

Commit

Permalink
fix(module: select): allow change both data source and value in one r…
Browse files Browse the repository at this point in the history
…ender period (#1720)

* fix(module:select): allow change both datasource and value in one render period

* Update Select.razor.cs

* Update Select.razor.cs

* Update Select.razor.cs
  • Loading branch information
anranruye authored Jul 11, 2021
1 parent 1542d36 commit 352b8ca
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions components/select/Select.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,24 +262,18 @@ public IEnumerable<TItem> DataSource
}
}

bool _valueHasChanged;

[Parameter]
public override TItemValue Value
{
get => _selectedValue;
set
{
var hasChanged = !EqualityComparer<TItemValue>.Default.Equals(value, _selectedValue);
if (hasChanged)
_valueHasChanged = !EqualityComparer<TItemValue>.Default.Equals(value, _selectedValue);
if (_valueHasChanged)
{
_selectedValue = value;
if (_isInitialized)
{
OnValueChange(value);
if (Form?.ValidateOnChange == true)
{
EditContext?.NotifyFieldChanged(FieldIdentifier);
}
}
}
}
}
Expand Down Expand Up @@ -532,6 +526,16 @@ protected override async Task OnParametersSetAsync()
if (SelectOptions == null)
CreateDeleteSelectOptions();

if (_valueHasChanged && _isInitialized)
{
_valueHasChanged = false;
OnValueChange(_selectedValue);
if (Form?.ValidateOnChange == true)
{
EditContext?.NotifyFieldChanged(FieldIdentifier);
}
}

await base.OnParametersSetAsync();
}

Expand Down

0 comments on commit 352b8ca

Please sign in to comment.