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

Set default item in topping dropdown when adding/removing #367

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
fix: set topping dropdown to default when no item has been selected
  • Loading branch information
FrancescoRepo committed Dec 2, 2023

Verified

This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
commit e643c0d9523a885a44d51813f3cc9309cf78f96b
8 changes: 6 additions & 2 deletions src/BlazingPizza.Client/Shared/ConfigurePizzaDialog.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@inject HttpClient HttpClient
@inject IJSRuntime JSRuntime


<div class="dialog-title">
@@ -27,7 +28,7 @@
}
else
{
<select class="custom-select" @onchange="ToppingSelected">
<select class="custom-select" @onchange="ToppingSelected" @ref="toppingsSelect">
<option value="-1" disabled selected>(select)</option>
@for (var i = 0; i < toppings.Count; i++)
{
@@ -63,6 +64,7 @@

@code {
List<Topping>? toppings;
ElementReference? toppingsSelect { get; set; }

[Parameter, EditorRequired] public Pizza Pizza { get; set; } = new();
[Parameter, EditorRequired] public EventCallback OnCancel { get; set; }
@@ -90,8 +92,10 @@
}
}

void RemoveTopping(Topping topping)
async Task RemoveTopping(Topping topping)
{
Pizza.Toppings.RemoveAll(pt => pt.Topping == topping);
if(!Pizza.Toppings.Any() && toppingsSelect != null)
await JSRuntime.InvokeVoidAsync("JsFunctions.setSelectedIndex", toppingsSelect, 0);
}
}
3 changes: 2 additions & 1 deletion src/BlazingPizza.Client/wwwroot/index.html
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
<body>
<div id="app">
<div class="loading-bar"></div>
</div>
</div>

<div id="blazor-error-ui">
An unhandled error has occurred.
@@ -29,5 +29,6 @@
<script src="_content/BlazingPizza.ComponentsLibrary/deliveryMap.js"></script>
<script src="_content/BlazingPizza.ComponentsLibrary/leaflet/leaflet.js"></script>
<script>navigator.serviceWorker.register('service-worker.js');</script>
<script src="js/functions.js"></script>
</body>
</html>
6 changes: 6 additions & 0 deletions src/BlazingPizza.Client/wwwroot/js/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
window.JsFunctions =
{
setSelectedIndex: function (element, index) {
element.selectedIndex = index;
}
};