beta This component version is ready to be used but is still in active development.

Fieldset form

The vf-form__fieldset is used to group a set related form inputs.

github location npm version

Usage

Use the vf-form__fieldset component to display a relationship between multiple form inputs. You can also need use a vf-form__fieldset inside of another vf-form__fieldset, this would be good to group multiple vf-form__checkbox inputs and allow for a vf-form__legend to give the inputs a heading or question. To make it more obvious what we are asking the site visitor to fill out and why, it is recommened to use a vf-form__legend within each vf_form__fieldset.

Variants

A Fieldset Legend
Nunjucks syntax

Depending on your environment you'll want to use render or include. As a rule of thumb: server-side use include, precompiled browser use render. If you're using vf-eleventy you should use include.

Using include

You'll need to pass a context object from your code or Yaml file (example), as well as the path to the Nunjucks template. Nunjucks' include is an abstraction of render and provides some additional portability.


{% set context fromYourYamlFile %}
- or -
{% set context = {
  "component-type": "form",
  "fieldset_legend": {
    "legend__text": "A Fieldset Legend"
  }
}
 %}
{% include "../path_to/vf-form__fieldset/vf-form__fieldset.njk" %}
                

Using render

This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include is not be available.

{% render '@vf-form__fieldset', {
  "component-type": "form",
  "fieldset_legend": {
    "legend__text": "A Fieldset Legend"
  }
} %}
                
HTML
<fieldset class="vf-form__fieldset | vf-stack vf-stack--400">
  <legend class="vf-form__legend">A Fieldset Legend</legend>
</fieldset>
              
Another Fieldset Legend

Something has gone terribly wrong.

Nunjucks syntax

Depending on your environment you'll want to use render or include. As a rule of thumb: server-side use include, precompiled browser use render. If you're using vf-eleventy you should use include.

Using include

You'll need to pass a context object from your code or Yaml file (example), as well as the path to the Nunjucks template. Nunjucks' include is an abstraction of render and provides some additional portability.


{% set context fromYourYamlFile %}
- or -
{% set context = {
  "component-type": "form",
  "fieldset__error": {
    "error": true,
    "helper_text": "Something has gone terribly wrong."
  },
  "fieldset_legend": {
    "legend__text": "Another Fieldset Legend"
  }
}
 %}
{% include "../path_to/vf-form__fieldset/vf-form__fieldset.njk" %}
                

Using render

This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include is not be available.

{% render '@vf-form__fieldset', {
  "component-type": "form",
  "fieldset__error": {
    "error": true,
    "helper_text": "Something has gone terribly wrong."
  },
  "fieldset_legend": {
    "legend__text": "Another Fieldset Legend"
  }
} %}
                
HTML
<fieldset class="vf-form__fieldset | vf-stack vf-stack--400">
  <legend class="vf-form__legend">Another Fieldset Legend</legend>

  <p class="vf-form__helper vf-form__helper--error">Something has gone terribly wrong.</p>
</fieldset>
              

Examples

Installation info

This repository is distributed with [npm][https://www.npmjs.com/]. After [installing npm][https://www.npmjs.com/get-npm] and yarn, you can install vf-form__fieldset with this command.

$ yarn add --dev @visual-framework/vf-form__fieldset

Changelog

Changelog

2.0.0-alpha.0

  • Moves the fieldset outside of vf-form folder.
  • Allows the templating of the fieldset
  • Removes unnecessary additional styling for vf-form__label when inside a fieldset.

1.1.1

  • style fieldset label as a heading 5

1.1.0

  • updates spacing design tokens
  • requires v2.0.0 of the vf-design-tokens package or newer

1.0.0

  • Adds fieldset

Assets



File system location: components/vf-form__fieldset

Find an issue on this page? Propose a change or discuss it.