Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mrpmorris committed Oct 16, 2023
2 parents da0192b + e9e5e84 commit 08b50e7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ In fact, even apply a value such as `false` will still activate them. The follow
`readonly` and `disabled`.

```html
<input readonly="false" disbabled="false"/>
<input readonly="false" disabled="false"/>
```

In razor views the rule is slightly different.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ An exception to this is when we wish to pass a lambda; lambdas must be escaped w
The following code shows how the `@onclick` directive is used to add the DOM onclick event to a rendered H1 element.

```razor
// Razor mark-up with @ref directive
// Razor mark-up with @onclick directive
<h1 @onclick=H1Clicked>Hello, world!</h1>
@code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ For example, the `preventDefault` attribute applied to the `@onclick` directive
a submit button from actually submitting a form.

```razor
<input type="submit" @onclick:preventdefault>
<input type="submit" @onclick:preventDefault>
```

In addition to these, it is also possible to assign values to some directive attributes in the following form:
Expand Down Expand Up @@ -165,8 +165,8 @@ And something similar to the following (again abridged) code for converting user

The code hooks into the HTML `onchange` event and then, via the binder, sets our member value when the event is triggered.

The different when setting the `@bind-value:format` directive attribute value is that the format we
provide passed in the generated code to both `BindConverter.Format` and `EventCallback.Factory.CreateBinder`.
The difference when setting the `@bind-value:format` directive attribute value is that the format we
provide is passed in the generated code to both `BindConverter.Format` and `EventCallback.Factory.CreateBinder`.

```cs
...BindConverter.FormatValue(Name, format: "yyyy-MM-dd");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public interface IOwnedDependency
public int InstanceNumber { get; }
}
public class OwnedDependency : IDependencyOne
public class OwnedDependency : IOwnedDependency
{
private static volatile int PreviousInstanceNumber;
Expand Down
8 changes: 8 additions & 0 deletions source/blazor-university-com/input/pages/forms/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ The key feature to the `EditForm` is its `Model` parameter. This parameter provi

Let's start by creating a class we can use with our `EditForm`. At this point a simple empty class will suffice.

```cs
public class Person
{
}
```

Edit the standard **index.razor** page as follows:

```razor {: .line-numbers}
@page "/"
<EditForm Model=@Person>
Expand All @@ -34,17 +37,21 @@ Edit the standard **index.razor** page as follows:
{
Person Person = new Person();
}
```

Line 9 creates an instance of a `Person` for our form to bind to. Line 3 creates an `EditForm` and sets its `Model` parameter to our instance. The preceding razor mark-up results in the following HTML.

```html
<form>
<input class="btn btn-primary" type="submit" value="Submit">
</form>
```

## Detecting form submission

When the user clicks the **Submit** button in the preceding example, the `EditForm` will trigger its `OnSubmit` event. We can use this event in our code to handle any business logic.

```razor
@page "/"
<h1>Status: @Status</h1>
Expand All @@ -63,6 +70,7 @@ When the user clicks the **Submit** button in the preceding example, the `EditFo
// Post data to the server, etc
}
}
```

Form submission will be covered in more depth in the [Handling form submission](/forms/handling-form-submission/) section.

0 comments on commit 08b50e7

Please sign in to comment.