Binding to FluentSelect SelectedOption #1701
Replies: 3 comments 1 reply
-
Dies it work as expected if you just use the form on a page without the dialog? |
Beta Was this translation helpful? Give feedback.
-
It also does not work if just using a regular page. In this code, gradesSelectedValue has the correct value as it is leaving OnInitialized. After seeing that it still doesn't work as expected, I added the label to display the Grade.Id.ToString. That causes a null reference exception. If I comment out the FluentSelect, the page loads and displays the Grade.Id in the label. @page "/applicants/{id:int}"
@inject ApplicantService ApplicantService
@inject GradeService GradeService
@inject NavigationManager Navigation
<h3>EditApplicant</h3>
<FluentBodyContent>
<EditForm EditContext="@editContext" FormName="applicant_details">
<DataAnnotationsValidator />
<div>
<FluentTextField Name="first_name" @bind-Value="applicant.FirstName" Label="First Name" />
<FluentValidationMessage For="@(() => applicant.FirstName)" />
</div>
<div>
<FluentTextField Name="last_name" @bind-Value="applicant.LastName" Label="Last Name" />
<FluentValidationMessage For="@(() => applicant.LastName)" />
</div>
<div>
<FluentSelect TOption="Grade"
Label="Select Grade"
Items="@grades"
OptionText="@(g => g.Name)"
OptionValue="@(g => g.Id.ToString())"
@bind-SelectedOption="applicant.Grade"
@bind-Value="@gradesSelectedValue"
Width="175px" />
<FluentValidationMessage For="@(() => applicant.Grade)" />
</div>
<p>gradesSelectedValue is @applicant.Grade.Id.ToString()</p>
</EditForm>
</FluentBodyContent>
@code {
[Parameter]
public int id { get; set; } = default!;
Applicant applicant;
EditContext editContext;
private IQueryable<Grade> grades;
private string gradesSelectedValue = "test";
protected override void OnInitialized()
{
applicant = ApplicantService.GetApplicants().Where(a => a.Id == id).First();
editContext = new EditContext(applicant);
grades = GradeService.GetGrades();
gradesSelectedValue = applicant.Grade.Id.ToString();
}
} |
Beta Was this translation helpful? Give feedback.
-
Did you find a workaround for this? I have the same problem. |
Beta Was this translation helpful? Give feedback.
-
I have an edit form in a dialog. I'm passing it an Applicant object.
Everything seems to work nicely, except I can't get the FluentSelect to bind to the Applicant.Grade object when the form loads.
The two text fields are populating correctly. However, the FluentSelect is always set to the first item in the list when the dialog page loads. The binding works if I go ahead and change the Grade in the list and save the object. The changed grade is reflected on my master/index page. What am I missing to set the correct value when the edit dialog loads?
Thanks for your help.
Beta Was this translation helpful? Give feedback.
All reactions