# Email field

Source: https://ecosphere.dev/docs/forms/email-field (Ecosphere 1.5). Install `vue-ecosphere` for Vue 3 or `react-ecosphere` for React 18.2+/19: same components, props, markup and stylesheet.

An email field with the mail glyph and its validation states.

`import { EcoEmailField } from "vue-ecosphere"`

## Email

Type an address and leave the field: it validates on blur.

Vue (vue-ecosphere):

```vue
<EcoEmailField v-model="work" label="Email" required placeholder="you@company.com"
  @validate="(ok) => (valid = ok)" first />
```

React (react-ecosphere):

```tsx
const [work, setWork] = useState("");
const [valid, setValid] = useState<boolean | null>(null);

<EcoEmailField value={work} onChange={setWork} label="Email" required placeholder="you@company.com"
  onValidate={setValid} first />
```

## Filled

Vue (vue-ecosphere):

```vue
<EcoEmailField v-model="filled" label="Email" hint="The address every notification goes to." first />
```

React (react-ecosphere):

```tsx
const [filled, setFilled] = useState("kiara.casmer@northwind.example");

<EcoEmailField value={filled} onChange={setFilled} label="Email" hint="The address every notification goes to." first />
```

## Bounced

Focus the field and leave it to see the error; fix the domain to clear it.

Vue (vue-ecosphere):

```vue
<EcoEmailField v-model="bounced" label="Email" first />
<!-- validates on blur: "That address is missing a domain, like .com." -->
```

React (react-ecosphere):

```tsx
const [bounced, setBounced] = useState("h.cole@example");

<EcoEmailField value={bounced} onChange={setBounced} label="Email" first />
{/* validates on blur: "That address is missing a domain, like .com." */}
```

## Read-only

A blocked control is always paired with the reason.

Vue (vue-ecosphere):

```vue
<EcoEmailField model-value="kiara.casmer@northwind.example" label="Sign-in email"
  disabled hint="Ask an owner to change the sign-in address." first />
```

React (react-ecosphere):

```tsx
<EcoEmailField value="kiara.casmer@northwind.example" label="Sign-in email"
  disabled hint="Ask an owner to change the sign-in address." first />
```

## API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `v-model` | `string` | "" | The address. |
| `validate` | `boolean` | true | Check on blur and say what is missing. Never while typing. |
| `error` | `string` | — | Your own error (e.g. a bounce); wins over the built-in check. |
| `label / required / hint / invalid / first / disabled / readonly / placeholder / id` | `—` | — | As on EcoTextField. |
| `@validate` | `(valid: boolean) => void` | — | After each blur check. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `value / onChange` | `string` | "" | The address. |
| `validate` | `boolean` | true | Check on blur and say what is missing. Never while typing. |
| `error` | `string` | — | Your own error (e.g. a bounce); wins over the built-in check. |
| `label / required / hint / invalid / first / disabled / readOnly / placeholder / id` | `—` | — | As on EcoTextField. Other input attributes (name, autoComplete, onBlur…) and the ref go to the input. |
| `onValidate` | `(valid: boolean) => void` | — | After each blur check. |
