Skip to main content

Form

<allegro-form> renders a form composed in the Allegro admin (under Forms) from your organization's user attributes. The authenticated member's current values are prefilled, submissions are validated against each attribute's validation rules, and the member's profile is updated in place.

The component only renders for authenticated members. If no member is signed in, the element stays empty — pair it with <allegro-content-gate> or <allegro-login-form> to prompt visitors to sign in first.

Usage

<allegro-form slug="profile-basics"></allegro-form>

Customized, with a custom success state:

<allegro-form slug="profile-basics" submit-text="Update profile">
<div slot="success">
<h2>All set!</h2>
<p>Your profile has been updated.</p>
</div>
</allegro-form>

Attributes

AttributeTypeDefaultDescription
slugtext(none)Slug of the form to render, as defined under Forms.
submit-texttextSaveLabel for the submit button.
success-headingtextThank you!Heading shown in the default success state.
success-texttextYour responses have been saved.Body text shown in the default success state.
previewbooleanfalseRender a static sample form and success state for style previews instead of fetching a real form.
tracking-datatext(none)JSON object of custom data merged into every tracked event.

States

StateTriggerDescription
formSuccessful load for an authenticated memberThe form's fields, prefilled with the member's current values.
successSuccessful submissionThe success slot when provided, otherwise a default confirmation.

Fields with display conditions show and hide live as the member fills out the form: a field configured to appear only when another field is checked, unchecked, has a value, or equals a specific value is re-evaluated on every change. Hidden fields are not submitted.

Slots

SlotAppears inDescription
successsuccessReplaces the default confirmation after a submission.
<allegro-form slug="profile-basics">
<div slot="success">
<h2>Saved!</h2>
<a href="/account">Back to your account</a>
</div>
</allegro-form>

Shadow Parts

For styling beyond what the CSS variables make available, elements can be targeted directly with the CSS ::part() selector.

allegro-form::part(submit) {
margin-bottom: 2rem;
}
PartAppears inDescription
formformThe rendered <form> element.
submitformThe submit button.
successsuccessWrapper around the success elements. Not rendered when the success slot is provided.
success-iconsuccessThe success icon.

Events

Dispatched

EventBubblesDetailDescription
allegro:form:successYes{ slug: string; values: Record<string, unknown> }Fired after a successful submission.
allegro:form:errorYes{ slug: string; error: string }Fired when a submission fails, including validation errors.

Both events are composed, so they cross shadow DOM boundaries.

document.addEventListener('allegro:form:success', (event) => {
console.log('Form saved:', event.detail.slug, event.detail.values);
});

Tracked Events

The component records the following events via the Allegro SDK.

EventWhenData
form_submittedAfter a successful submission{ form_slug: string }

Validation

Values are validated server-side on submission:

  • Fields marked required in the form builder must be filled in (when visible).
  • Each value must pass the attribute's type check and any validation rules configured on the attribute (length, regex, contains, email, numeric bounds).
  • Error messages configured on the form field or on the attribute's validation rules are shown next to the failing field.

A max_length rule also sets a maxlength hint on the rendered input.

CSS Variables

Style the form through CSS custom properties on the element.

allegro-form {
--form--button--background: #0f766e;
--form--input--border-radius: 0;
}

Defaults written below as u(n) mean n times --form--base-font-size, the component's sizing unit: u(0.5) is half that unit, u(1.25) is one and a quarter. The unit defaults to the page's rem. If the host page sets a root font-size other than the usual 16px, pin it so the form sizes the same either way:

allegro-form {
--form--base-font-size: 16px;
}

Layout & Typography

VariableDefaultDescription
--form--base-font-sizevar(--allegro--font-size, 1rem)Base sizing unit for the component.
--form--font-familyvar(--allegro--font-family, system-ui, sans-serif)Font family.
--form--colorvar(--allegro--color-text, black)Text color.
--form--gapu(1)Vertical gap between fields.

Labels & Inputs

VariableDefaultDescription
--form--label--font-sizeu(0.875)Label font size.
--form--label--font-weight600Label font weight.
--form--required--colorvar(--allegro--color-error, #b91c1c)Color of the required asterisk.
--form--input--backgroundwhiteInput background.
--form--input--border1px solid #d4d4d4Input border.
--form--input--border-radiusvar(--allegro--radius, u(0.375))Input border radius.
--form--input--font-sizeu(1)Input font size.
--form--input--paddingu(0.5) u(0.75)Input padding.
--form--input--focus-border-colorvar(--allegro--color-primary, #171717)Border color of a focused input.
--form--checkbox--accent-colorvar(--allegro--color-primary, #171717)Checkbox accent color.
--form--tooltip--color#737373Tooltip text color.
--form--tooltip--font-sizeu(0.75)Tooltip font size.

Errors

VariableDefaultDescription
--form--error--colorvar(--allegro--color-error, #b91c1c)Error message color.
--form--error--font-sizeu(0.875)Error message font size.

Button & Success State

VariableDefaultDescription
--form--button--backgroundvar(--allegro--color-primary, #171717)Submit button background.
--form--button--colorwhiteSubmit button text color.
--form--button--border-radiusvar(--allegro--radius, u(0.375))Submit button border radius.
--form--button--font-sizeu(1)Submit button font size.
--form--button--paddingu(0.5) u(1.25)Submit button padding.
--form--success--paddingu(1.5) 0Default success state padding.
--form--success--icon-backgroundvar(--allegro--color-success, #16a34a)Success icon circle background.
--form--success--heading-font-sizeu(1.25)Success heading font size.
--form--success--body-color#525252Success body text color.
--form--success--body-font-sizeu(0.9375)Success body font size.

Example: Dark Background

.dark-section allegro-form {
--form--color: #f5f5f5;
--form--input--background: #262626;
--form--input--border: 1px solid #404040;
--form--tooltip--color: #a3a3a3;
--form--button--background: #f5f5f5;
--form--button--color: #171717;
}