SmartPasteButton
SmartPasteButton fills a form from the text in the clipboard, such as an email or a signature, with AI. It describes the fields of the closest reactive, template-driven or Signal Forms form to the model, checks and converts the values it returns, and announces the filled fields. It works with any model through a small adapter to your own backend.
Import #
import { SmartPasteButton, SmartPasteField } from '@exhaustive-ui/core/smartpastebutton';
import { provideAIAssist } from '@exhaustive-ui/core/aiassist';The same entry point exports the SmartPasteField directive, pSmartPasteField, which describes a field to the model. The adapter contract, shared with InlineAIAssist and SmartTextarea, comes from @exhaustive-ui/core/aiassist.
Basic #
Put the button in a form. It reads the clipboard, sends the text with a description of the fields of the form to the adapter, and fills the fields with the values of the answer. Copy the signature below, then press Smart paste. When the browser does not give access to the clipboard, a dialog asks to paste the text.
The demos of this page answer offline with fakeAIAssistAdapter, which reads the text with a few regular expressions; the Adapter section plugs a real model.
Amy Elsner Head of Design, Northwind Traders [email protected] ยท +1 555 0134
Adapter #
SmartPasteButton sends no request of its own: an adapter connects it to the model of your choice, through an endpoint of your application that holds the API key. Never put the key in the browser. The request has the smart-paste task, the pasted text, instructions that ask for a JSON object, and a context with the described fields and the date of today, to read relative dates such as "next Monday".
The answer is an object of values by field name, or its JSON text, even inside a Markdown code block or streamed in chunks. Give the adapter to the button with adapter, or to all the components with provideAIAssist; the same endpoint serves InlineAIAssist and SmartTextarea. The AbortSignal of the request cancels it when the user presses Stop.
import { provideAIAssist } from '@exhaustive-ui/core/aiassist';
provideAIAssist(async ({ task, text, instructions, context, signal }) => {
const response = await fetch('/api/ai', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ task, text, instructions, context }),
signal
});
if (!response.ok) {
throw new Error(`The server answered ${response.status}`);
}
return response.text(); // '{"customer": "Globex Corporation", "quantity": 12}'
});The request sent for the form of the Fields section looks like this:
Fields and Preview #
Each field is described to the model by its name, its label (a label element, aria-labelledby or aria-label), its type, taken from the input or the value of the control, its options for a select, and whether it is required. The pSmartPasteField directive adds a description, for example to tell a date of birth from the date of a message, and can set the smartPasteLabel, the smartPasteType and the smartPasteOptions of a component such as Select, or leave a field out with smartPasteIgnore. The fields property does the same by name, without touching the template.
The answer is checked before it is applied: unknown, disabled and read-only fields are skipped, values are converted to the type of the field ("36 years" to 36, "yes" to true, a date written in words to a Date, a label to the value of its option), and a value that cannot be converted is dropped. Fields that hold a value are kept unless overwrite is set. With confirm, a dialog lists the values to apply first.
Hello, this is Bernardo from Globex Corporation, sent on 2026-11-30. Could you send us 12 units, delivered in Germany on December 15, 2026? Thanks!
Forms #
Template Driven #
In a template-driven form, the button fills the ngModel fields of the closest form, and the properties they are bound to.
We are four colleagues coming to Lyon next week, and we will need a parking space for our car.
Signal Forms #
With Angular Signal Forms, give the field tree to for. The values are written to the fields, which are marked as dirty, so that the validation of the form applies to them as if they had been typed.
Hi, I am Ioni Bowcher, please register me with ioni.bowcher at example dot com.
Accessibility #
Screen Reader
SmartPasteButton is a native button named by its text, "Smart paste", which becomes its aria-label with iconOnly; its icon is hidden from assistive technologies. While the form is filled, the button reads "Stop" and the component is aria-busy. A polite live region then announces the result, such as "4 fields filled: Full name, Company, Email, Phone", or the error, which is also shown next to the button with a retry button.
The paste dialog and the preview dialog are native modal dialogs, named by their title and described by their instructions; the focus moves into them and returns to the button when they close. In the preview, each value is a checkbox labelled by the name of the field and the value, with the value it replaces. The fields that were filled are marked with a data-p-smart-pasted attribute, highlighted until they are edited. The texts are translated with labels, and the smartPaste and smartPasteFilled keys of the aria translation.
Keyboard Support
| Key | Function |
|---|---|
| enter / space | Fills the form from the clipboard, or stops the request while it runs. |
| tab | Moves through the text area, the checkboxes and the buttons of a dialog. |
| escape | Closes a dialog without filling the form. |