|
8 | 8 |
|
9 | 9 | <EditForm Model="@order" OnValidSubmit="@HandleValidSubmit" OnInvalidSubmit="@HandleInvalidSubmit">
|
10 | 10 | <DataAnnotationsValidator />
|
11 |
| - |
| 11 | + |
12 | 12 | <div class="container mt-4">
|
13 | 13 | <h4>Order Details</h4>
|
14 | 14 | <div class="mb-3">
|
|
32 | 32 | <InputText id="customerEmail" @bind-Value="order.CustomerDetails.Email" class="form-control" />
|
33 | 33 | <ValidationMessage For="@(() => order.CustomerDetails.Email)" />
|
34 | 34 | </div>
|
35 |
| - <div class="mb-3"> |
36 |
| - <label for="customerAge" class="form-label">Age</label> |
37 |
| - <InputNumber id="customerAge" @bind-Value="order.CustomerDetails.Age" class="form-control" /> |
38 |
| - <ValidationMessage For="@(() => order.CustomerDetails.Age)" /> |
39 |
| - </div> |
40 | 35 |
|
41 | 36 | <h5>Shipping Address</h5>
|
42 | 37 | <div class="card mb-3">
|
43 | 38 | <div class="card-body">
|
44 |
| - <div class="mb-3"> |
45 |
| - <label for="shippingStreet" class="form-label">Street</label> |
46 |
| - <InputText id="shippingStreet" @bind-Value="order.CustomerDetails.ShippingAddress.Street" class="form-control" /> |
47 |
| - <ValidationMessage For="@(() => order.CustomerDetails.ShippingAddress.Street)" /> |
48 |
| - </div> |
49 |
| - <div class="mb-3"> |
50 |
| - <label for="shippingZipCode" class="form-label">Zip Code</label> |
51 |
| - <InputText id="shippingZipCode" @bind-Value="order.CustomerDetails.ShippingAddress.ZipCode" class="form-control" /> |
52 |
| - <ValidationMessage For="@(() => order.CustomerDetails.ShippingAddress.ZipCode)" /> |
| 39 | + <div class="row"> |
| 40 | + <div class="mb-3 col-sm-8"> |
| 41 | + <label for="shippingStreet" class="form-label">Street</label> |
| 42 | + <InputText id="shippingStreet" @bind-Value="order.CustomerDetails.ShippingAddress.Street" class="form-control" /> |
| 43 | + <ValidationMessage For="@(() => order.CustomerDetails.ShippingAddress.Street)" /> |
| 44 | + </div> |
| 45 | + <div class="mb-3 col-sm"> |
| 46 | + <label for="shippingZipCode" class="form-label">Zip Code</label> |
| 47 | + <InputText id="shippingZipCode" @bind-Value="order.CustomerDetails.ShippingAddress.ZipCode" class="form-control" /> |
| 48 | + <ValidationMessage For="@(() => order.CustomerDetails.ShippingAddress.ZipCode)" /> |
| 49 | + </div> |
53 | 50 | </div>
|
54 | 51 | </div>
|
55 | 52 | </div>
|
|
70 | 67 | <button type="button" class="btn btn-sm btn-danger" @onclick="() => RemoveOrderItem(itemIndex)">Remove</button>
|
71 | 68 | </div>
|
72 | 69 | <div class="card-body">
|
73 |
| - <div class="mb-3"> |
74 |
| - <label for="@($"productName_{itemIndex}")" class="form-label">Product Name</label> |
75 |
| - <InputText id="@($"productName_{itemIndex}")" @bind-Value="order.OrderItems[itemIndex].ProductName" class="form-control" /> |
76 |
| - <ValidationMessage For="@(() => order.OrderItems[itemIndex].ProductName)" /> |
77 |
| - </div> |
78 | 70 | <div class="row">
|
79 |
| - <div class="col-md-6 mb-3"> |
| 71 | + <div class="mb-3 col-sm-8"> |
| 72 | + <label for="@($"productName_{itemIndex}")" class="form-label">Product Name</label> |
| 73 | + <InputText id="@($"productName_{itemIndex}")" @bind-Value="order.OrderItems[itemIndex].ProductName" class="form-control" /> |
| 74 | + <ValidationMessage For="@(() => order.OrderItems[itemIndex].ProductName)" /> |
| 75 | + </div> |
| 76 | + <div class="mb-3 col-sm"> |
80 | 77 | <label for="@($"quantity_{itemIndex}")" class="form-label">Quantity</label>
|
81 | 78 | <InputNumber id="@($"quantity_{itemIndex}")" @bind-Value="order.OrderItems[itemIndex].Quantity" class="form-control" />
|
82 | 79 | <ValidationMessage For="@(() => order.OrderItems[itemIndex].Quantity)" />
|
83 | 80 | </div>
|
84 |
| - <div class="col-md-6 mb-3"> |
85 |
| - <label for="@($"price_{itemIndex}")" class="form-label">Price</label> |
86 |
| - <InputNumber id="@($"price_{itemIndex}")" @bind-Value="order.OrderItems[itemIndex].Price" class="form-control" TValue="decimal" ParseErrorMessage="Please enter a valid price." /> |
87 |
| - <ValidationMessage For="@(() => order.OrderItems[itemIndex].Price)" /> |
88 |
| - </div> |
89 | 81 | </div>
|
90 | 82 | </div>
|
91 | 83 | </div>
|
|
95 | 87 | {
|
96 | 88 | <p>No order items. Add one below.</p>
|
97 | 89 | }
|
98 |
| - |
| 90 | + |
99 | 91 | <button type="button" class="btn btn-success mb-3" @onclick="AddOrderItem">Add Order Item</button>
|
100 | 92 |
|
101 | 93 | <hr />
|
|
118 | 110 | <ul>
|
119 | 111 | @foreach (var item in order.OrderItems)
|
120 | 112 | {
|
121 |
| - <li>@item.Quantity x @item.ProductName at @item.Price.ToString("C")</li> |
| 113 | + <li>@item.Quantity x @item.ProductName</li> |
122 | 114 | }
|
123 | 115 | </ul>
|
124 | 116 | </div>
|
125 | 117 | }
|
126 | 118 |
|
127 | 119 | @if (submitFailed)
|
128 | 120 | {
|
129 |
| - <div class="mt-4 alert alert-danger" role="alert"> |
| 121 | + <div class="mt-4 alert alert-danger" role="alert"> |
130 | 122 | <h4>Form Submission Failed!</h4>
|
131 | 123 | <p>Please correct the validation errors and try again.</p>
|
132 | 124 | </div>
|
|
141 | 133 | private void HandleValidSubmit()
|
142 | 134 | {
|
143 | 135 | Console.WriteLine("Form submitted successfully!");
|
144 |
| - // Here you would typically process the order |
145 |
| - // For demo purposes, we'll just display a success message |
146 | 136 | submitted = true;
|
147 | 137 | submitFailed = false;
|
148 |
| - // To see the data in console: |
149 |
| - // System.Text.Json.JsonSerializer.Serialize(order); |
150 | 138 | }
|
151 | 139 |
|
152 | 140 | private void HandleInvalidSubmit()
|
|
159 | 147 | private void AddOrderItem()
|
160 | 148 | {
|
161 | 149 | order.OrderItems.Add(new OrderItemModel());
|
162 |
| - submitted = false; // Reset submission status |
| 150 | + submitted = false; |
163 | 151 | submitFailed = false;
|
164 | 152 | }
|
165 | 153 |
|
|
169 | 157 | {
|
170 | 158 | order.OrderItems.RemoveAt(index);
|
171 | 159 | }
|
172 |
| - submitted = false; // Reset submission status |
| 160 | + submitted = false; |
173 | 161 | submitFailed = false;
|
174 | 162 | }
|
175 | 163 | }
|
0 commit comments