# Forms & Events

Course: [Blazor](https://www.devtutorials.ai/learn/blazor) · Section: User Interaction
Source: https://www.devtutorials.ai/learn/blazor/user-interaction/forms-and-events

> Forms and events in Blazor: input components with @bind-Value, one-way and two-way binding, click, mouse, keyboard, focus and change events, EditForm and models, custom inputs, OnSubmit and resetting a form.

## Forms Overview

- A **form** is a part of a page where the user types or picks things, like a name, a number or a date.
- Blazor gives you ready-made **input components**, like `InputText` and `InputNumber`.
- Each input is linked to a C# value. When the user types, the C# value changes. This link is called **data binding**.
- When the user clicks or presses a key, that is an **event**. Your C# code can react to it.

**Real-World Example:**

- Ravi wants an online order form for his tea shop.
- The customer types a name, picks a tea and a cup size, and chooses a pickup date.
- When the customer clicks **Place order**, the page shows "Thanks, Asha! 2 cups of Masala Tea."

<figure className="blz-fig">
<svg viewBox="0 0 640 180" role="img" aria-labelledby="fig-fe-bind">
  <title id="fig-fe-bind">Animation: the user types Asha in a text box. A dot carries the text to the C# field order.Name in the code. Then a dot carries it back to the page, which shows Hello, Asha.</title>
  <defs><marker id="fig-fe-bind-a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M0 0 L10 5 L0 10 z" style={{ fill: "var(--muted)" }} /></marker></defs>
  <rect className="box" x="20" y="40" width="190" height="110" rx="10" />
  <text className="t m" x="115" y="66" textAnchor="middle" style={{ fontSize: 12 }}>The page</text>
  <rect x="40" y="80" width="150" height="28" rx="5" style={{ fill: "var(--surface, #fff)", stroke: "var(--border, #ccc)" }} />
  <text className="t m" x="50" y="99" style={{ fontSize: 12 }}>Asha<animate attributeName="opacity" values="0;1;1" keyTimes="0;0.15;1" dur="5s" repeatCount="indefinite" /></text>
  <text className="t" x="115" y="135" textAnchor="middle" style={{ fontSize: 12 }}>Hello, Asha<animate attributeName="opacity" values="0;0;1;1" keyTimes="0;0.7;0.75;1" dur="5s" repeatCount="indefinite" /></text>
  <rect className="pur" x="410" y="40" width="210" height="110" rx="10" />
  <text className="t m" x="515" y="66" textAnchor="middle" style={{ fontSize: 12 }}>C# code</text>
  <text className="t m" x="515" y="100" textAnchor="middle" style={{ fontSize: 12 }}>order.Name = "Asha"<animate attributeName="opacity" values="0.25;0.25;1;1" keyTimes="0;0.35;0.4;1" dur="5s" repeatCount="indefinite" /></text>
  <path className="line" d="M210 80 C300 60 330 60 406 80" markerEnd="url(#fig-fe-bind-a)" />
  <path className="line" d="M410 120 C330 140 300 140 214 120" markerEnd="url(#fig-fe-bind-a)" />
  <text className="t" x="310" y="52" textAnchor="middle" style={{ fontSize: 11 }}>user types</text>
  <text className="t" x="310" y="160" textAnchor="middle" style={{ fontSize: 11 }}>Blazor shows the new value</text>
  <circle r="7" style={{ fill: "#7c3aed" }}>
    <animate attributeName="cx" values="210;210;406;406;214;214" keyTimes="0;0.15;0.38;0.5;0.72;1" dur="5s" repeatCount="indefinite" />
    <animate attributeName="cy" values="80;80;80;120;120;120" keyTimes="0;0.15;0.38;0.5;0.72;1" dur="5s" repeatCount="indefinite" />
  </circle>
</svg>
<figcaption>Data binding: the input and the C# value stay the same, in both directions.</figcaption>
</figure>

## Form Components and Data Binding

- Blazor's input components are `InputText`, `InputNumber`, `InputDate` and more. Each one draws a normal HTML input.
- You link an input to a value with `@bind-Value`, for example `<InputText @bind-Value="order.Name" />`.
- Input components must sit inside an `<EditForm>`. Think of `EditForm` as the box around the form. You learn it in detail later in this lesson.
- `EditForm` needs a **model**: a C# object that holds the form's values, like `order`.

### InputText and InputTextArea

- `InputText` is a one-line text box, for a name.
- `InputTextArea` is a bigger box with many lines, for a note.
- Both work with `string` values.

In the below example, `InputText` is linked to `order.Name` and `InputTextArea` to `order.Note`. The text under the form shows both values.

      <p>Name: <InputText @bind-Value="order.Name" /></p>
      <p>Note: <InputTextArea @bind-Value="order.Note" rows="2" /></p>

<p>Hello, @order.Name!</p>
<p>Your note: @order.Note</p>

@code {
      private TeaOrder order = new();

      private class TeaOrder
      {
          public string Name { get; set; } = "Asha";
          public string Note { get; set; } = "Less sugar, please.";
      }
}
`,
  }}
/>

- Change the name, then press **Tab** or click outside the box. The greeting changes.

`InputText` updates the value when you **leave** the box, not on every key press. That is the normal `change` event of an HTML input.

### InputNumber and InputDate

- `InputNumber` is a box for numbers, like `int` or `decimal`. It does not accept letters.
- `InputDate` shows a date picker. It works with `DateTime` or `DateOnly`.

In the below example, `InputNumber` sets the number of cups and `InputDate` sets the pickup date. The bill uses both.

      <p>Cups: <InputNumber @bind-Value="order.Cups" /></p>
      <p>Pickup: <InputDate @bind-Value="order.Pickup" /></p>

<p>@order.Cups cups × ₹20 = ₹@(order.Cups * 20)</p>
<p>Pickup day: @order.Pickup.ToString("dd MMM yyyy")</p>

@code {
      private TeaOrder order = new();

      private class TeaOrder
      {
          public int Cups { get; set; } = 2;
          public DateTime Pickup { get; set; } = DateTime.Today;
      }
}
`,
  }}
/>

- Change the cups to **3**, then click outside the box. The bill changes to ₹60.

### InputCheckbox

- `InputCheckbox` is a tick box. It works with a `bool` value: `true` when ticked, `false` when not.

In the below example, `InputCheckbox` is linked to `order.Sugar`. The text shows "with sugar" or "no sugar".

      <label>

<p>Masala Tea, @(order.Sugar ? "with sugar" : "no sugar")</p>

@code {
      private TeaOrder order = new();

      private class TeaOrder
      {
          public bool Sugar { get; set; }
      }
}
`,
  }}
/>

### InputSelect

- `InputSelect` is a drop-down list. You write each choice as an `<option>`.
- The value of the chosen `<option>` goes into the linked field.

In the below example, `InputSelect` is linked to `order.Size`. The three options are Small, Medium and Large.

          <option value="Small">Small (₹15)</option>
          <option value="Medium">Medium (₹20)</option>
          <option value="Large">Large (₹25)</option>

<p>You picked: @order.Size</p>

@code {
      private TeaOrder order = new();

      private class TeaOrder
      {
          public string Size { get; set; } = "Medium";
      }
}
`,
  }}
/>

### InputRadio and InputRadioGroup

- **Radio buttons** are round choices. The user can pick only **one** of them.
- `InputRadioGroup` holds the group and is linked to the value.
- Each `InputRadio` is one choice, with its own `Value`.

In the below example, `InputRadioGroup` is linked to `order.Delivery`. The two `InputRadio` choices are Pickup and Home delivery.

          <label><InputRadio Value="@("Pickup")" /> Pickup</label>
          <label><InputRadio Value="@("Home delivery")" /> Home delivery</label>

<p>Delivery: @order.Delivery</p>

@code {
      private TeaOrder order = new();

      private class TeaOrder
      {
          public string Delivery { get; set; } = "Pickup";
      }
}
`,
  }}
/>

- `Value="@("Pickup")"` gives the choice a C# string. Writing only `Value="Pickup"` also works for strings.

### InputFile

- `InputFile` lets the user choose a file from their computer, like a photo.
- It does not use `@bind-Value`. Instead, its `OnChange` event runs a method when a file is chosen.
- The method gets the file's name, size and type. It does not need an `EditForm`.

In the below example, `InputFile` calls `FileChosen` when a file is picked. The page shows the file's name and size.

@if (fileName != null)
{
      <p>File: @fileName (@fileSize bytes)</p>
}

@code {
      private string? fileName;
      private long fileSize;

      private void FileChosen(InputFileChangeEventArgs e)
      {
          fileName = e.File.Name;
          fileSize = e.File.Size;
      }
}
`,
  }}
/>

To read what is inside the file, use `e.File.OpenReadStream()`. It allows 500 KB by default. Pass a bigger limit for bigger files, like `OpenReadStream(2_000_000)`.

### One-Way and Two-Way Binding (@bind)

- **One-way binding** only shows a value: `<input value="@name" />`. Typing in the box does **not** change `name`.
- **Two-way binding** shows the value **and** changes it when the user types: `<input @bind="name" />`.
- `@bind` works on plain HTML inputs. `@bind-Value` is the same idea for components like `InputText`.
- By default, `@bind` updates when you leave the box. Add `@bind:event="oninput"` to update on every key press.

<figure className="blz-fig">
<svg viewBox="0 0 640 180" role="img" aria-labelledby="fig-fe-ways">
  <title id="fig-fe-ways">Two panels. One-way: an arrow goes only from the C# field name to the input box. Two-way: arrows go both ways between the C# field and the input box.</title>
  <defs><marker id="fig-fe-ways-a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M0 0 L10 5 L0 10 z" style={{ fill: "var(--muted)" }} /></marker></defs>
  <rect className="box" x="20" y="20" width="290" height="140" rx="10" />
  <text className="t m" x="165" y="44" textAnchor="middle" style={{ fontSize: 13, fontWeight: 700 }}>One-way: value="@name"</text>
  <rect className="pur" x="40" y="70" width="100" height="40" rx="8" />
  <text className="t m" x="90" y="95" textAnchor="middle" style={{ fontSize: 12 }}>name</text>
  <rect className="blu" x="190" y="70" width="100" height="40" rx="8" />
  <text className="t m" x="240" y="95" textAnchor="middle" style={{ fontSize: 12 }}>input box</text>
  <path className="line" d="M140 90 H186" markerEnd="url(#fig-fe-ways-a)" />
  <text className="t" x="165" y="140" textAnchor="middle" style={{ fontSize: 11 }}>Typing does not change name</text>
  <rect className="box" x="330" y="20" width="290" height="140" rx="10" />
  <text className="t m" x="475" y="44" textAnchor="middle" style={{ fontSize: 13, fontWeight: 700 }}>Two-way: @bind="name"</text>
  <rect className="pur" x="350" y="70" width="100" height="40" rx="8" />
  <text className="t m" x="400" y="95" textAnchor="middle" style={{ fontSize: 12 }}>name</text>
  <rect className="grn" x="500" y="70" width="100" height="40" rx="8" />
  <text className="t m" x="550" y="95" textAnchor="middle" style={{ fontSize: 12 }}>input box</text>
  <path className="line" d="M450 82 H496" markerEnd="url(#fig-fe-ways-a)" />
  <path className="line" d="M500 100 H454" markerEnd="url(#fig-fe-ways-a)" />
  <text className="t" x="475" y="140" textAnchor="middle" style={{ fontSize: 11 }}>Typing changes name</text>
</svg>
<figcaption>One-way binding only shows the value. Two-way binding also sends changes back.</figcaption>
</figure>

In the below example, the first box uses one-way binding and the second uses two-way binding with `oninput`. Type in each box and watch the last line.

<p>Two-way: <input @bind="name" @bind:event="oninput" /></p>

<p>name = @name</p>

@code {
      private string name = "Asha";
}
`,
  }}
/>

- Typing in the first box does nothing to `name`. Typing in the second box changes `name` at once, and the first box shows it too.

## Event Handling

- An **event** is something the user does: a click, a key press, a mouse move.
- You handle an event with `@on` and the event name, like `@onclick="AddCup"`.
- After your method runs, Blazor renders the component again, so the page shows the new values.

<figure className="blz-fig">
<svg viewBox="0 0 640 150" role="img" aria-labelledby="fig-fe-event">
  <title id="fig-fe-event">Animation: a click on the Add cup button sends a dot to the C# method AddCup, which changes cups from 1 to 2. Then Blazor renders and the page shows Cups: 2.</title>
  <defs><marker id="fig-fe-event-a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M0 0 L10 5 L0 10 z" style={{ fill: "var(--muted)" }} /></marker></defs>
  <rect className="blu" x="20" y="60" width="140" height="50" rx="10" />
  <text className="t m" x="90" y="90" textAnchor="middle" style={{ fontSize: 12 }}>Click: Add cup</text>
  <rect className="pur" x="230" y="60" width="170" height="50" rx="10" />
  <text className="t m" x="315" y="90" textAnchor="middle" style={{ fontSize: 12 }}>AddCup(): cups++</text>
  <rect className="org" x="460" y="60" width="160" height="50" rx="10" />
  <text className="t m" x="540" y="82" textAnchor="middle" style={{ fontSize: 12 }}>Render</text>
  <text className="t" x="540" y="100" textAnchor="middle" style={{ fontSize: 11 }}>Cups: 1<animate attributeName="opacity" values="1;1;0;0" keyTimes="0;0.7;0.72;1" dur="4s" repeatCount="indefinite" /></text>
  <text className="t" x="540" y="100" textAnchor="middle" style={{ fontSize: 11 }} opacity="0">Cups: 2<animate attributeName="opacity" values="0;0;1;1" keyTimes="0;0.7;0.72;1" dur="4s" repeatCount="indefinite" /></text>
  <path className="line" d="M160 85 H226" markerEnd="url(#fig-fe-event-a)" />
  <path className="line" d="M400 85 H456" markerEnd="url(#fig-fe-event-a)" />
  <circle r="7" cy="85" style={{ fill: "#7c3aed" }}>
    <animate attributeName="cx" values="90;315;540;540" keyTimes="0;0.35;0.7;1" dur="4s" repeatCount="indefinite" />
  </circle>
</svg>
<figcaption>An event runs your method. Then Blazor renders the new values.</figcaption>
</figure>

### Click Events

- `@onclick` runs a method when the element is clicked.
- To pass a value to the method, use a small **lambda** (a short inline function): `@onclick="() => Order("Masala Tea")"`.

In the below example, each button calls `Order` with a different tea name. The page shows the last tea and the number of orders.

<button @onclick='() => Order("Ginger Tea")'>Ginger Tea</button>

<p>Orders: @count</p>
<p>Last order: @lastTea</p>

@code {
      private int count;
      private string lastTea = "none";

      private void Order(string tea)
      {
          count++;
          lastTea = tea;
      }
}
`,
  }}
/>

### Mouse Events

- `@onmouseover` runs when the mouse moves onto an element. `@onmouseout` runs when it leaves.
- `@onmousemove` runs as the mouse moves. Its method can take `MouseEventArgs`, which has the position, like `e.OffsetX`.

In the below example, the card turns purple while the mouse is over it, and the page shows where the mouse is.

      Masala Tea card
</div>

<p>@(over ? $"Mouse at {x}, {y}" : "Move the mouse over the card")</p>

@code {
      private bool over;
      private double x, y;

      private void Move(MouseEventArgs e)
      {
          x = e.OffsetX;
          y = e.OffsetY;
      }
}
`,
  }}
/>

### Keyboard Events

- `@onkeydown` runs when a key is pressed in an element, like a text box.
- Its method can take `KeyboardEventArgs`. `e.Key` tells you which key, for example `"Enter"`.

In the below example, typing a tea name and pressing **Enter** adds it to the list.

<ul>
      @foreach (var t in teas)
      {
          <li>@t</li>
      }
</ul>

@code {
      private string tea = "";
      private List<string> teas = new() { "Masala Tea" };

      private void KeyPressed(KeyboardEventArgs e)
      {
          if (e.Key == "Enter" && tea != "")
          {
              teas.Add(tea);
              tea = "";
          }
      }
}
`,
  }}
/>

### Focus and Change Events

- `@onfocus` runs when the user enters a box (clicks or tabs into it). `@onblur` runs when the user leaves it.
- `@onchange` runs when a value is changed and confirmed, like picking from a list. Its method can take `ChangeEventArgs`, and `e.Value` is the new value.

In the below example, the status line shows when the name box has focus, and `@onchange` reads the size picked in the list.

<p>Size:
      <select @onchange="SizeChanged">
          <option>Small</option>
          <option>Medium</option>
          <option>Large</option>
      </select>
</p>

<p>@status</p>
<p>Size: @size</p>

@code {
      private string status = "Click the name box";
      private string size = "Small";

      private void SizeChanged(ChangeEventArgs e)
      {
          size = e.Value?.ToString() ?? "";
      }
}
`,
  }}
/>

Use `@onchange` **or** `@bind` on an element, not both. `@bind` already uses the change event, so the build fails if you add both.

## Working with EditForm

### EditForm and Model

- `EditForm` is Blazor's form component. It draws an HTML `<form>`.
- `Model` is the object that holds the form's values. Each input is linked to one property of the model.
- It is good practice to put the model class in its own file, like `Models/TeaOrder.cs`.

<figure className="blz-fig">
<svg viewBox="0 0 640 200" role="img" aria-labelledby="fig-fe-editform">
  <title id="fig-fe-editform">EditForm holds a model called order. Three inputs inside the form, InputText, InputNumber and InputSelect, each link to one property of order: Name, Cups and Size.</title>
  <defs><marker id="fig-fe-editform-a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M0 0 L10 5 L0 10 z" style={{ fill: "var(--muted)" }} /></marker></defs>
  <rect className="box" x="20" y="20" width="300" height="160" rx="10" />
  <text className="t m" x="170" y="44" textAnchor="middle" style={{ fontSize: 13, fontWeight: 700 }}>EditForm Model="order"</text>
  <rect className="blu" x="40" y="60" width="260" height="30" rx="6" />
  <text className="t m" x="170" y="80" textAnchor="middle" style={{ fontSize: 12 }}>InputText</text>
  <rect className="blu" x="40" y="98" width="260" height="30" rx="6" />
  <text className="t m" x="170" y="118" textAnchor="middle" style={{ fontSize: 12 }}>InputNumber</text>
  <rect className="blu" x="40" y="136" width="260" height="30" rx="6" />
  <text className="t m" x="170" y="156" textAnchor="middle" style={{ fontSize: 12 }}>InputSelect</text>
  <rect className="pur" x="420" y="40" width="200" height="130" rx="10" />
  <text className="t m" x="520" y="64" textAnchor="middle" style={{ fontSize: 13, fontWeight: 700 }}>order (model)</text>
  <text className="t m" x="440" y="98" style={{ fontSize: 12 }}>Name</text>
  <text className="t m" x="440" y="124" style={{ fontSize: 12 }}>Cups</text>
  <text className="t m" x="440" y="150" style={{ fontSize: 12 }}>Size</text>
  <path className="line" d="M300 75 C360 75 380 94 432 94" markerEnd="url(#fig-fe-editform-a)" />
  <path className="line" d="M300 113 C360 113 380 120 432 120" markerEnd="url(#fig-fe-editform-a)" />
  <path className="line" d="M300 151 C360 151 380 146 432 146" markerEnd="url(#fig-fe-editform-a)" />
</svg>
<figcaption>Each input in the EditForm is linked to one property of the model.</figcaption>
</figure>

In the below example, `Models/TeaOrder.cs` holds the model class. `OrderForm.razor` puts three inputs in an `EditForm`, and the summary shows the whole order.

      <p>Name: <InputText @bind-Value="order.Name" /></p>
      <p>Cups: <InputNumber @bind-Value="order.Cups" /></p>
      <p>Tea:
              <option>Masala Tea</option>
              <option>Ginger Tea</option>
      </p>

<p>@order.Name wants @order.Cups cups of @order.Tea.</p>

@code {
      private TeaOrder order = new();
}
`,
    "Models/TeaOrder.cs": `namespace BlazorApp.Models;

public class TeaOrder
{
      public string Name { get; set; } = "Asha";
      public int Cups { get; set; } = 2;
      public string Tea { get; set; } = "Masala Tea";
}
`,
  }}
/>

### Custom Input Components (@bind-Value)

- You can make your **own** input component and use `@bind-Value` on it, like the built-in ones.
- The component needs two parameters: `Value` (the value it shows) and `ValueChanged` (an `EventCallback` it calls with the new value).
- `@bind-Value="order.Cups"` sets `Value` and listens to `ValueChanged` for you.

In the below example, `CupStepper.razor` shows − and + buttons. Each click calls `ValueChanged`, so `order.Cups` in `OrderForm.razor` changes.

      Cups: <CupStepper @bind-Value="order.Cups" />

<p>Bill: ₹@(order.Cups * 20)</p>

@code {
      private TeaOrder order = new();

      private class TeaOrder
      {
          public int Cups { get; set; } = 1;
      }
}
`,
    "Components/CupStepper.razor": `<button type="button" @onclick="() => Change(-1)">−</button>
<b> @Value </b>
<button type="button" @onclick="() => Change(1)">+</button>

@code {
      [Parameter] public int Value { get; set; }
      [Parameter] public EventCallback<int> ValueChanged { get; set; }

      private async Task Change(int by)
      {
          int next = Math.Max(0, Value + by);
          await ValueChanged.InvokeAsync(next);
      }
}
`,
  }}
/>

- Click **+** twice. The stepper shows 3, and the bill in the parent shows ₹60.

Buttons inside an `EditForm` **submit the form** by default. Add `type="button"` to buttons that only do something else, like the − and + buttons.

## Form Submission

### OnSubmit

- **Submitting** a form means sending it: the user clicks a button with `type="submit"` or presses **Enter** in a box.
- `OnSubmit` on the `EditForm` names the method that runs then.
- With validation (checking the values), you use `OnValidSubmit` instead. That runs only when every value is correct.

In the below example, the **Place order** button submits the form. `OnSubmit` runs `PlaceOrder`, which shows a thank-you message.

      <p>Name: <InputText @bind-Value="order.Name" /></p>
      <p>Cups: <InputNumber @bind-Value="order.Cups" /></p>
      <button type="submit">Place order</button>

<p>@message</p>

@code {
      private TeaOrder order = new();
      private string message = "";

      private void PlaceOrder()
      {
          message = $"Thanks, {order.Name}! {order.Cups} cups are on the way.";
      }

      private class TeaOrder
      {
          public string Name { get; set; } = "Asha";
          public int Cups { get; set; } = 2;
      }
}
`,
  }}
/>

## Form Reset

- **Resetting** a form means emptying it, so the user can start again.
- In Blazor, you reset by giving the model a **new, empty object**: `order = new();`. The inputs show the new values at once.
- Use `type="button"` on a **Clear** button, so it does not submit the form.

In the below example, **Place order** shows a message and then resets the form. **Clear** only resets it.

      <p>Name: <InputText @bind-Value="order.Name" /></p>
      <p>Cups: <InputNumber @bind-Value="order.Cups" /></p>
      <button type="submit">Place order</button>
      <button type="button" @onclick="Reset">Clear</button>

<p>@message</p>

@code {
      private TeaOrder order = new() { Name = "Asha", Cups = 2 };
      private string message = "";

      private void PlaceOrder()
      {
          message = $"Order saved for {order.Name}.";
          Reset();
      }

      private void Reset() => order = new();

      private class TeaOrder
      {
          public string Name { get; set; } = "";
          public int Cups { get; set; } = 1;
      }
}
`,
  }}
/>

- Click **Clear**. The name box empties and the cups go back to 1.

## Common mistakes

<div className="tscroll">

| Mistake | Wrong idea | Correct idea | What goes wrong |
|---|---|---|---|
| An `InputText` outside an `EditForm` | Input components work anywhere | Put input components inside an `EditForm` | An error: it needs a cascading `EditContext` |
| `<input value="@name" />` to read typing | `value=` is two-way | Use `@bind="name"` | Typing does not change `name` |
| A normal button inside an `EditForm` | Buttons only run `@onclick` | Add `type="button"` to non-submit buttons | The form submits on every click |
| `@onclick="Order(tea)"` | You can call the method with a value directly | Use a lambda: `@onclick="() => Order(tea)"` | A build error |
| A custom input with only `Value` | `Value` is enough for `@bind-Value` | Add `EventCallback<T> ValueChanged` | A build error on `@bind-Value` |

</div>

## Check Yourself

## Exercises

## What to Remember

- Input components (`InputText`, `InputNumber`, `InputDate`, `InputCheckbox`, `InputSelect`, `InputRadioGroup`) go inside an `EditForm` and use `@bind-Value`.
- `InputFile` uses `OnChange` to get the chosen file.
- `value="@x"` is one-way. `@bind="x"` is two-way. `@bind:event="oninput"` updates on every key.
- Handle events with `@onclick`, `@onmouseover`, `@onkeydown`, `@onfocus`, `@onblur` and `@onchange`. Event args like `KeyboardEventArgs` give the details.
- `EditForm` takes a `Model`. A custom input needs `Value` and `ValueChanged` for `@bind-Value`.
- `OnSubmit` runs when the form is submitted.
- Reset a form with `order = new();`. Give non-submit buttons `type="button"`.

Next: **Form Validation**
