i need help please,
when enter to EditForm in edit with Value (example : 87912e32-b1a2-49d3-85d8-c72a4d6daef7 ) in SfDropDownList and DataSource is empty .. the Value set to null
the following code is show :
<SfDropDownList TValue="Guid?" TItem="EmployeeDropDownListViewModel" @bind-Value="ViewModel.EmployeeRowId"
ShowClearButton="true" DataSource="employees"
AllowFiltering="true" FilterType="Syncfusion.Blazor.DropDowns.FilterType.Contains"
Placeholder="@_sharedLocalizer["Choose"]"
<DropDownListFieldSettings Value="RowId" Text="Name"></DropDownListFieldSettings>
</SfDropDownList>
@code {
private List<EmployeeDropDownListViewModel> employees;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
try
{
// here ViewModel.EmployeeRowId is 87912e32-b1a2-49d3-85d8-c72a4d6daef7
employees = await HttpService.GetAsync<List<EmployeeDropDownListViewModel>> ($"/api/EmployeeDropDownListViewModels/GetEmployeesForDropDownList");
// here ViewModel.EmployeeRowId become null and validation is fire
await base.OnAfterRenderAsync(firstRender);
}
catch (Exception exception)
{
Log.Error(exception, Utilities.GetExceptionErrorString(exception));
_toaster.ShowToaster(exception.Message, ToasterType.Error);
}
}
}
}
|
<EditForm Model="ChemOrderTable">
<SfDropDownList @ref="DropObj" TValue="Guid?" TItem="EmployeeDropDownListViewModel"
ShowClearButton="true" DataSource="employees"
AllowFiltering="true" FilterType="Syncfusion.Blazor.DropDowns.FilterType.Contains"
Placeholder="Choose">
<DropDownListFieldSettings Value="RowId" Text="Name"></DropDownListFieldSettings>
<DropDownListEvents TValue="Guid?" TItem="EmployeeDropDownListViewModel" Filtering="OnFiltering"></DropDownListEvents>
</SfDropDownList>
</EditForm>
@code {
public async Task OnFiltering(FilteringEventArgs e)
{
e.PreventDefaultAction = true;
query = new Query().Where(new WhereFilter()
{
Field = "RowId",
value = e.Text,
Operator = "startswith",
IgnoreCase = true
});
await this.DropObj.Filter(employees, query);
}
} |
I'm Sorry, i told you the value binding will be null if DataSource is list empty (example, if i load datasource in OnAfterRenderAsync ).. and this not my order
|
@code {
private List<EmployeeDropDownListViewModel> employees;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
try
{
// here ViewModel.EmployeeRowId is 87912e32-b1a2-49d3-85d8-c72a4d6daef7
employees = await HttpService.GetAsync<List<EmployeeDropDownListViewModel>>($"/api/EmployeeDropDownListViewModels/GetEmployeesForDropDownList");
// here ViewModel.EmployeeRowId become null and validation is fire
ViewModel.EmployeeRowId = "87912e32-b1a2-49d3-85d8-c72a4d6daef7";
await base.OnAfterRenderAsync(firstRender);
}
catch (Exception exception)
{
Log.Error(exception, Utilities.GetExceptionErrorString(exception));
_toaster.ShowToaster(exception.Message, ToasterType.Error);
}
}
}
}
|