Skip to content

Commit 86befce

Browse files
committed
Line edits2
1 parent abf4458 commit 86befce

6 files changed

+21
-21
lines changed

learn-pr/aspnetcore/blazor-improve-how-forms-work/2-attach-csharp-code-dom-events-blazor-event-handlers.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ quiz:
2020
choices:
2121
- content: "C# events"
2222
isCorrect: false
23-
explanation: "C# events do not properly transfer between components"
23+
explanation: "C# events don't properly transfer between components"
2424
- content: "EventCallback"
2525
isCorrect: true
2626
explanation: "EventCallbacks look like parameters on a component and can be specified on a Blazor page or another component"
@@ -34,7 +34,7 @@ quiz:
3434
explanation: "preventDefault prevents the default action in the DOM element from executing"
3535
- content: "return false"
3636
isCorrect: false
37-
explanation: "return false was a technique to stop an event in other JavaScript frameworks, but does not prevent the default action"
37+
explanation: "return false was a technique to stop an event in other JavaScript frameworks, but doesn't prevent the default action"
3838
- content: "throw new Exception()"
3939
isCorrect: false
4040
explanation: "Throwing an exception might stop the default action from executing, but it also raises an error that you might not want your application users to interact with"

learn-pr/aspnetcore/blazor-improve-how-forms-work/6-validate-user-input-implicitly.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ quiz:
2020
choices:
2121
- content: "ValidationMessage"
2222
isCorrect: false
23-
explanation: "The ValidationMessage component will display the message for one component, not a summary"
23+
explanation: "The ValidationMessage component displays the message for one component, not a summary"
2424
- content: "DataAnnotationsValidator"
2525
isCorrect: false
26-
explanation: "This component activates the validations in the EditForm, but does not display a summary of validation message"
26+
explanation: "This component activates the validations in the EditForm, but doesn't display a summary of validation message"
2727
- content: "ValidationSummary"
2828
isCorrect: true
2929
explanation: "This component displays a summary of all the validation messages in a submitted form"
30-
- content: "Which of these is NOT a standard input elements that comes with Blazor?"
30+
- content: "Which of these choices is NOT a standard input element that comes with Blazor?"
3131
choices:
3232
- content: "Guid"
3333
isCorrect: true
34-
explanation: "Guid is not part of the standard input elements provided by Blazor"
34+
explanation: "Guid isn't part of the standard input elements provided by Blazor"
3535
- content: "CreditCard"
3636
isCorrect: false
3737
explanation: "CreditCard is one of the standard input elements provided by Blazor"

learn-pr/aspnetcore/blazor-improve-how-forms-work/includes/2-attach-csharp-code-dom-events-blazor-event-handlers.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In this unit, you'll look in detail at the third option; how to create a Blazor
88

99
## Handle an event with Blazor and C#
1010

11-
Each element in the HTML markup of a Blazor app supports many events. Most of these events correspond to the DOM events available in regular web applications, but you can also create user-defined events that are triggered by writing code. To capture an event with Blazor, you write a C# method that handles the event, then bind the event to the method with a Blazor directive. For a DOM event, the Blazor directive shares the same name as the equivalent HTML event, such as `@onkeydown` or `@onfocus`. For example, the sample app generated by using the Blazor Server App contains the following code on the **Counter.razor** page. This page displays a button. When the user selects the button, the `@onclick` event triggers the `IncrementCount` method that increments a counter indicating how many times the button has been clicked. The value of the counter variable is displayed by the \<p\> element on the page:
11+
Each element in the HTML markup of a Blazor app supports many events. Most of these events correspond to the DOM events available in regular web applications, but you can also create user-defined events that are triggered by writing code. To capture an event with Blazor, you write a C# method that handles the event, then bind the event to the method with a Blazor directive. For a DOM event, the Blazor directive shares the same name as the equivalent HTML event, such as `@onkeydown` or `@onfocus`. For example, the sample app generated by using the Blazor Server App contains the following code on the **Counter.razor** page. This page displays a button. When the user selects the button, the `@onclick` event triggers the `IncrementCount` method that increments a counter indicating how many times the button has been clicked. The \<p\> element on the page displays the value of the counter variable:
1212

1313
```razor
1414
@page "/counter"
@@ -84,7 +84,7 @@ A traditional web application uses JavaScript to capture and process events. You
8484

8585
Besides the syntactic differences in the two versions of the event handler, you should note the following functional differences:
8686

87-
- JavaScript does not prefix the name of the event with an `@` sign; it's not a Blazor directive.
87+
- JavaScript doesn't prefix the name of the event with an `@` sign; it's not a Blazor directive.
8888
- In the Blazor code, you specify the name of the event-handling method when you attach it to an event. In JavaScript, you write a statement that calls the event-handling method; you specify round brackets and any parameters required.
8989
- Most importantly, the JavaScript event handler runs in the browser, on the client. If you're building a Blazor Server App, the Blazor event handler runs on the server and only updates the browser with any changes made to the UI when the event handler completes. Additionally, the Blazor mechanism enables an event handler to access static data that's shared between sessions; the JavaScript model doesn't. However, handling some frequently occurring events such as `@onmousemove` can cause the user interface to become sluggish because they require a network round-trip to the server. You might prefer to handle events such as these in the browser, using JavaScript.
9090

@@ -93,7 +93,7 @@ Besides the syntactic differences in the two versions of the event handler, you
9393
9494
## Handle events asynchronously
9595

96-
By default, Blazor event handlers are synchronous. If an event handler performs a potentially long-running operation, such as calling a web service, the thread on which the event handler runs will be blocked until the operation completes. This can lead to poor response in the user interface. To combat this, you can designate an event handler method as asynchronous. Use the C# `async` keyword. The method must return a `Task` object. You can then use the `await` operator inside the event handler method to initiate any long-running tasks on a separate thread and free the current thread for other work. When a long-running task completes, the event handler resumes. The example event handler below runs a time-consuming method asynchronously:
96+
By default, Blazor event handlers are synchronous. If an event handler performs a potentially long-running operation, such as calling a web service, the thread on which the event handler runs will be blocked until the operation completes. This can lead to poor response in the user interface. To combat this, you can designate an event handler method as asynchronous. Use the C# `async` keyword. The method must return a `Task` object. You can then use the `await` operator inside the event handler method to initiate any long-running tasks on a separate thread and free the current thread for other work. When a long-running task completes, the event handler resumes. The example event handler that follows runs a time-consuming method asynchronously:
9797

9898
```razor
9999
<button @onclick="DoWork">Run time-consuming operation</button>
@@ -144,7 +144,7 @@ The following image shows the result when the user selects the button:
144144
:::image type="content" source="../media/2-change-focus.png" alt-text="Screenshot of the web page after the user has clicked the button to set the focus to the input element.":::
145145

146146
> [!NOTE]
147-
> An app should only direct the focus to a specific control for a specific reason, such as to ask the user to modify input after an error. Don't use focusing to force the user to navigate through the elements on a page in a fixed order. This can be very frustrating to the user who might want to revisit elements to change their input.
147+
> An app should only direct the focus to a specific control for a specific reason, such as to ask the user to modify input after an error. Don't use focusing to force the user to navigate through the elements on a page in a fixed order. This can be frustrating to the user who might want to revisit elements to change their input.
148148
149149
## Write inline event handlers
150150

@@ -318,7 +318,7 @@ namespace WebApplication.Data
318318

319319
The `key` field contains the value entered by the user, and the `TransformedKey` field will hold the transformed value of the key when it has been processed.
320320

321-
In this example, the `EventCallback` object is a component parameter, and its value is supplied when the component is created. This action is performed by another component, named `TextTransformer`:
321+
In this example, the `EventCallback` object is a component parameter, and its value is supplied when the component is created. The component named `TextTransformer` performs this action:
322322

323323
```razor
324324
@page "/texttransformer"

learn-pr/aspnetcore/blazor-improve-how-forms-work/includes/4-take-advantage-power-blazor-forms.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ The following image shows an example of the page running:
8585

8686
The HTML `<form>` element supports the `<input>` element to enable the user to enter data. The `<input>` has a `type` property that specifies the type of the input and how it should be displayed; as a number, a text box, a radio button, a check box, a button, and so on.
8787

88-
Blazor has its own set of components designed to work specifically with the `<EditForm>` element and support data binding among other features. The following table lists these components. When Blazor renders a page containing these components, they are converted to the corresponding HTML `<input>` elements listed in the table. Some of the Blazor components are generic; the type parameter is ascertained by the Blazor runtime depending on the type of the data bound to the element:
88+
Blazor has its own set of components designed to work specifically with the `<EditForm>` element and support data binding among other features. The following table lists these components. When Blazor renders a page containing these components, they're converted to the corresponding HTML `<input>` elements listed in the table. Some of the Blazor components are generic; the Blazor runtime ascertains the type paramater depending on the type of the data bound to the element:
8989

9090
| Input component | Rendered as (HTML) |
9191
|---------------------------|------------------------------|
@@ -180,12 +180,12 @@ When you run the form, it looks like this:
180180

181181
## Handle form submission
182182

183-
You've seen that you can use an `EditForm` to modify data in the underlying model. When the changes are complete, you can submit the form to validate the data on the server and save the changes. Blazor supports two types of validation; declarative and programmatic. Declarative validation rules operate on the client, in the browser. They're useful for performing basic client-side validation before data is transmitted to the server. Server-side validation is useful for handling complex scenarios that are not available with declarative validation, such as cross-checking the data in a field against data from other sources. A real-world application should utilize a combination of client-side and server-side validation. The client-side validation traps basic user input errors and prevents many cases of invalid data being sent to the server for processing. Server-side validation ensures that a user request to save data doesn't attempt to bypass data validation and store incomplete or corrupt data.
183+
You've seen that you can use an `EditForm` to modify data in the underlying model. When the changes are complete, you can submit the form to validate the data on the server and save the changes. Blazor supports two types of validation; declarative and programmatic. Declarative validation rules operate on the client, in the browser. They're useful for performing basic client-side validation before data is transmitted to the server. Server-side validation is useful for handling complex scenarios that aren't available with declarative validation, such as cross-checking the data in a field against data from other sources. A real-world application should utilize a combination of client-side and server-side validation. The client-side validation traps basic user input errors and prevents many cases of invalid data being sent to the server for processing. Server-side validation ensures that a user request to save data doesn't attempt to bypass data validation and store incomplete or corrupt data.
184184

185185
> [!NOTE]
186-
> You can also trap JavaScript events such as `onchange` and `oninput`, and the Blazor equivalent `@onchange` and `@oninput` events for many controls in an `EditForm`. You can use these events to examine and validate data programmatically, on a field-by-field basis, before the user submits the form. However, this approach is not recommended. It can be frustrating to a user to have validation messages appear as they enter each keystroke or tab between fields. Save validation for when the user has completed their input.
186+
> You can also trap JavaScript events such as `onchange` and `oninput`, and the Blazor equivalent `@onchange` and `@oninput` events for many controls in an `EditForm`. You can use these events to examine and validate data programmatically, on a field-by-field basis, before the user submits the form. However, this approach isn't recommended. It can be frustrating to a user to have validation messages appear as they enter each keystroke or tab between fields. Save validation for when the user has completed their input.
187187
188-
An `EditForm` has three events that run when it is submitted:
188+
An `EditForm` has three events that run when it's submitted:
189189

190190
- `OnValidSubmit`: This event is triggered if the input fields successfully pass the validation rules defined by their validation attributes.
191191
- `OnInvalidSubmit`: This event is triggered if any of the input fields on the form fail the validation defined by their validation attributes.
@@ -204,8 +204,8 @@ The `EditForm` tracks the state of the current object acting as model, including
204204
205205
The following example shows the `EditForm` from the previous example with a submit button. The `EditForm` captures the `OnSubmit` event to validate the changes made to a T-shirt object. In this example, only certain combinations of values are allowed:
206206
207-
- Red T-shirts are not available in the Extra Large size.
208-
- Blue T-shirts are not available in the Small or Medium sizes.
207+
- Red T-shirts aren't available in the Extra Large size.
208+
- Blue T-shirts aren't available in the Small or Medium sizes.
209209
- White T-shirts have a maximum price of $50.
210210
211211
If an illegal combination is detected, the `Message` field on the form displays the reason for the validation failure. If the fields are valid, the data is processed and the data is saved (the logic for this process isn't shown).
@@ -225,7 +225,7 @@ If an illegal combination is detected, the `Message` field on the form displays
225225
226226
private async Task ValidateData(EditContext editContext)
227227
{
228-
if (editContext.Model is not Shirt shirt)
228+
if (editContext.Model isn't Shirt shirt)
229229
{
230230
Message = "T-Shirt object is invalid";
231231
return;

learn-pr/aspnetcore/blazor-improve-how-forms-work/includes/5-exercise-create-address-form-blazor-components.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ In this exercise, you'll replace the current HTML fields with a Blazor component
4646
1. In the file explorer, expand **Shared**, then select **AddressEditor.razor**.
4747
4848
1. Select the **Edit** menu, then select **Replace**.
49-
1. In the first field, enter `<input` in the replace field enter `<InputText`, then select replace all.
49+
1. In the first field enter `<input`, in the replace field enter `<InputText`, and then select replace all.
5050
5151
:::image type="content" source="../media/5-replace-input-elements.png" alt-text="Screenshot of Visual Studio Code and the text replace dialog.":::
5252
5353
1. Select the **Edit** menu, then select **Replace**.
54-
1. In the first field, enter `@bind=` in the replace field enter `@bind-Value=`, then select replace all.
54+
1. In the first field enter `@bind=`, in the replace field enter `@bind-Value=`, and then select replace all.
5555
1. Remove the `@ref="startName"` code on the Name field.
5656
1. Remove all the code below the Parameter declaration in the `@code` block. The block should now look like this.
5757

learn-pr/aspnetcore/blazor-improve-how-forms-work/includes/7-exercise-add-server-client-side-data-validation-address-form.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ In this exercise, you'll replace the current server-side validation to use data
6767

6868
:::image type="content" source="../media/7-show-validation-errors.png" alt-text="Screenshot of the error messages for each field.":::
6969

70-
This interaction improves the error checks for each field, but the error for each field would be much better next to the field it's related to.
70+
This interaction improves the error checks for each field, but the error for each field would be better next to the field it's related to.
7171

7272
1. Press <kbd>Shift</kbd> + <kbd>F5</kbd> to stop the app from running.
7373

0 commit comments

Comments
 (0)