Forms

The eds-form component provides a declarative, JSON-driven form system with built-in validation, conditional fields, grouped sections, and analytics tracking.

When to Use

ScenarioApproach
Simple data capture (1-5 fields)Single eds-form with a flat fields array
Multi-section input (5+ fields)Use groups to organize fields into labeled sections
Conditional flowsAdd condition rules to fields so they show/hide based on other field values
File uploadsUse type: "dropzone" or type: "file" field types
Surveys & ratingsUse type: "rating" or type: "nps" field types

Basic Form

Pass fields as a JSON array. Each field needs at minimum a name, label, and type:

Field Types

The form supports all eds-input-field types plus special types:

TypeDescription
textSingle-line text input
emailEmail with format validation
passwordPassword with masked input
numberNumeric input with min/max/step
textareaMulti-line text area
selectDropdown select with options
checkboxSingle or grouped checkboxes
radioRadio button group
rangeSlider input
fileFile picker (eds-input-file)
dropzoneDrag-and-drop file upload (eds-input-dropzone)
ratingStar rating (eds-rating)
npsNet Promoter Score 0-10 scale (eds-nps)
hiddenHidden field (not rendered, included in submission)

Validation

Fields validate in real-time as the user types. The form prevents submission until all required fields pass validation.

Required Fields

Custom Validation

Fields support minLength, maxLength, min, max, and pattern-based validation. Error messages display inline below each field.

Error Handling

When submission fails validation:

  1. An error banner appears at the top of the form
  2. Each invalid field shows its specific error message
  3. Re-validation happens as the user corrects input
  4. The submit button re-enables once all errors are resolved

Grouped Fields

Organize complex forms into sections using groups:

Conditional Fields

Show or hide fields based on other field values using condition rules:

Form Styles

StyleDescription
defaultStandard layout, no background
shadowCard-style with shadow elevation
brandBrand-themed with accent colors

Handling Submissions

Listen for the form event. The event detail contains the submission data and validation status:

const form = document.querySelector('eds-form');
form.addEventListener('form', (e) => {
  const { event, validated, value, success } = e.detail;

  if (event === 'submit' && validated) {
    // All fields passed validation
    console.log('Form data:', value);
  }

  if (event === 'input') {
    // Real-time field change
    console.log('Field changed:', e.detail.field, e.detail.value);
  }
});

Pre-populating Data

Use initData to populate the form with existing values:

Or programmatically:

const form = document.querySelector('eds-form');
form.setData({ firstName: 'Nikolaos', email: 'user@ebrains.eu' });

Analytics

Every form interaction is tracked automatically:

ActionEvent
Field input{ tag: 'eds-form', name: 'fieldName', action: 'input' }
Non-validated submit{ tag: 'eds-form', name: 'submit/non-validated', action: 'click' }
Validated submit{ tag: 'eds-form', name: 'submit/validated', action: 'click' }

Best Practices

  • Keep forms short — split complex flows into steps using eds-steps
  • Use groups for forms with more than 5 fields
  • Always set required on fields that must be filled
  • Provide hint text for fields with specific format requirements
  • Use condition on fields to reduce visual clutter
  • Show a success toast or alert after submission