Skip to content

Commit

Permalink
Merge pull request #93 from Blazored/fix-for-disabled-bug
Browse files Browse the repository at this point in the history
Fixed bug when control is disabled and bound to null value
  • Loading branch information
chrissainty authored Dec 6, 2019
2 parents b56c3e4 + 035665a commit d80279f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
19 changes: 19 additions & 0 deletions samples/BlazorClientSide/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@

<hr />

<h1>Blazored Typeahead - Disabled (Null Value)</h1>

<BlazoredTypeahead SearchMethod="@GetPeopleLocal"
@bind-Value="@SelectedPersonNull"
Disabled="IsDisabled"
placeholder="Search by first name...">
<SelectedTemplate Context="person">
@person.Firstname
</SelectedTemplate>
<ResultTemplate Context="person">
@person.Firstname @person.Lastname
</ResultTemplate>
</BlazoredTypeahead>

<button class="btn btn-primary" style="margin-top: 20px;" @onclick="@(() => IsDisabled = !IsDisabled)">@(IsDisabled ? "Enable" : "Disable")</button>

<hr />

<h1>Blazored Typeahead - Binding to different type</h1>

<BlazoredTypeahead SearchMethod="GetPeopleLocal"
Expand Down Expand Up @@ -164,6 +182,7 @@
private List<Person> People = new List<Person>();

private Person SelectedPerson;
private Person SelectedPersonNull;
private int? SelectedPersonId;
private IList<Person> SelectedPeople;
private FormExample FormModel = new FormExample();
Expand Down
19 changes: 19 additions & 0 deletions samples/BlazorServerSide/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@

<hr />

<h1>Blazored Typeahead - Disabled (Null Value)</h1>

<BlazoredTypeahead SearchMethod="@GetPeopleLocal"
@bind-Value="@SelectedPersonNull"
Disabled="IsDisabled"
placeholder="Search by first name...">
<SelectedTemplate Context="person">
@person.Firstname
</SelectedTemplate>
<ResultTemplate Context="person">
@person.Firstname @person.Lastname
</ResultTemplate>
</BlazoredTypeahead>

<button class="btn btn-primary" style="margin-top: 20px;" @onclick="@(() => IsDisabled = !IsDisabled)">@(IsDisabled ? "Enable" : "Disable")</button>

<hr />

<h1>Blazored Typeahead - Binding to different type</h1>

<BlazoredTypeahead SearchMethod="GetPeopleLocal"
Expand Down Expand Up @@ -135,6 +153,7 @@
private List<Person> People = new List<Person>();

private Person SelectedPerson;
private Person SelectedPersonNull;
private int? SelectedPersonId;
private IList<Person> SelectedPeople;
private FormExample FormModel = new FormExample();
Expand Down
9 changes: 6 additions & 3 deletions src/Blazored.Typeahead/BlazoredTypeahead.razor
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
}
else
{
<div class="blazored-typeahead__input-mask" tabindex="0">
@SelectedTemplate(Value)
</div>
if (Value != null)
{
<div class="blazored-typeahead__input-mask" tabindex="0">
@SelectedTemplate(Value)
</div>
}
}
</div>
<div class="blazored-typeahead__input-icon blazored-typeahead__input-icon--disabled">
Expand Down

0 comments on commit d80279f

Please sign in to comment.