Edit this page

up.form up.form.group(element)
JavaScript function

This feature is experimental. It may be changed or removed in a future version.

Returns the form group for the given element.

By default a form group is a <fieldset> element or any container with an [up-form-group] attribute. This can be configured in up.form.config.groupSelectors.

Form groups may be nested. This function returns the closest group around the given element. If no closer group is found, the <form> element is returned.


This is a form with two groups:

    <label for="email">E-mail</label>
    <input type="text" name="email" id="email">
    <label for="password">Password</label>
    <input type="text" name="password" id="password">

We can now retrieve the form group for any element in the form:

let passwordField = document.querySelector('#password')
let group = up.form.group(passwordField) // returns second <fieldset>


element Element

The element for which to find a form group.

Return value

The closest form group around the given element.

If no better group can be found, the form element is returned.