Advanced Usage

Conditional fields

Put one or more constraint objects directly on an element. Each object names a source field, comparison, and effect:

{
	$type: 'input',
	id: 'other-reason',
	name: 'otherReason',
	label: 'Please specify',
	constraints: [
		{
			field: 'reason',
			operator: 'equals',
			value: 'other',
			action: 'show',
		},
	],
}

Supported operators are equals, not_equals, contains, not_contains, greater_than, less_than, is_empty, and is_not_empty. Effects are show, hide, enable, disable, and require.

Import the browser helper from @schema-engine/forms/browser:

import { GDPRConsent } from '@schema-engine/forms/browser';

GDPRConsent.grantConsent();
GDPRConsent.saveDraft('contact', { email: 'reader@example.com' });
const draft = GDPRConsent.loadDraft('contact');

Grant consent before saving a draft. Drafts use the autosave_<formId> key shared with the auto-save and reset actions. GDPRConsent.revokeConsent() clears drafts that the browser auto-save adapter or GDPRConsent.saveDraft wrote, under either the default key or a custom storageKey. Consent is browser storage state; applications provide their own React subscriptions, disclosure, and retention policy.

Analytics

import { GTMTracker } from '@schema-engine/forms/browser';

GTMTracker.pushFormEvent('form_submit', undefined, { formId: 'contact' });

pushFormEvent accepts form_mount, form_step_complete, form_submit, and form_abandon. Applications choose the values they send. The helper filters common sensitive field names, but does not replace application data minimization.

For config-driven analytics, register the gtm_event action and place an action config in form.actions. See Actions.