Skip to content

EnForm ​

Preview ​

Props ​

NameDescriptionDefaultControl
fields

An array of objects containing the entries for the form. Each object will map to the props of any 'EnInput*' component.

array<Field>
unknowncomplex object
horizontal

Sets the layout of the fields in the form by adding the 'form-horizontal' css class

boolean
false
gridFields

Lays the fields out as a grid row.

flex-row carries margin: 0 -15px, and only a col-* child cancels it — so a form whose fields are not col-* loses 15px on both sides, silently. That is the right default for a form built from fields, where every group is a col-*. Turn it off for a form that lays its own rows out — form-group-inline, a grid, fields wrapped in sections — so the fields sit inside their container rather than 15px outside it.

Note horizontal is not the way to avoid the row: it swaps flex-row for .form-horizontal .form-group, which carries the same negative margin plus a clearfix whose pseudo-elements become grid items and reorder a form-group-inline row.

boolean
true
submitText

Sets the readable text for the default submit button.

string
"Submit"
submitClass

Sets the CSS class for the default submit button.

string
"btn-success"
cancelText

Sets the readable text for the default cancel button.

string
"Cancel"
cancelClass

Sets the CSS class for the default cancel button.

string
"btn-link"
errorMessage

Sets the bottom error message when a form is submitted with validation errors.

string
"Please fix all errors before submitting."
labelClass

Sets the class used for the label column when using horizontal layout.

string
"col-md-3"
inputClass

Sets the class used for the input column when using horizontal layout.

string
"col-md-9"
showRequired

Displays asterisk (*) next to required field labels

boolean
true
renderSubmitButton

Whether or not to render the submit button responsible for the submit event for the form.

boolean
true
renderCancelButton

Whether or not to render the cancel button responsible for the cancel event for the form.

boolean
false
isSubmitting

Whether or not to render the 'loading spinner' icon indicating that the form is in the middle of a submit process.

boolean
false
preventMultiSubmit

Adds double-click protection to form submit button, in the form of preventing a second submit. Form will need to be re-rendered via a page reload or key change in order to reset.

boolean
true
formGroupClass

Sets class for each dynamically created form group. Use this to create additional columns of fields.

string
"col-12"
displayOnly

Sets all inputs in the fields json to display only. Also hides submit and cancel buttons.

boolean
false
emptyValue

What every display-only field shows in place of an empty value, unless a field sets its own. true is an em dash; a string is shown as given.

string | boolean
false
disableSubmit

Disables submit button and form submit event.

boolean
false
disableForm

Disables form and removes submit button.

boolean
false
validateOnMount

Validates form immediately on mount.

boolean
false
inModal

Sets CSS classes so that component can be used within a modal without needing to separate the buttons.

boolean
false
useTrackedJson

Uses internally tracked JSON values from the form for the returned data instead of serializing the form DOM.

boolean
false
showRequiredLegend

Shows the required legend at the top of the form when showRequired is true.

boolean
false

Slots ​

form-top

Places content above the form

Variables
NameTypeDescription
errorsarray

An list of error messages from invalid fields.

metaobject

The current validation state of the form.

fields

Slot to add all fields of the form. The parent container has the `flex-row` class which requires direct children to have `col*` classes. See examples for further explanation.

Variables
NameTypeDescription
fieldsarray.<Field>

A list of fields passed to the component via json.

errorsarray

An list of error messages from invalid fields.

metaobject

The current validation state of the form.

inputGroupPropsInputGroupProps

The form's own layout values, to pass through to groups here that should match the ones generated from fields. Any group can set its own instead.

<dynamic:setSlotName(field)>

No description

Variables
NameTypeDescription
nameunknown—
fieldunknown—

buttons

Replaces default buttons.

Variables
NameTypeDescription
submitFormfunction

Method that can be used to submit the form

metaobject

The current validation state of the form.

resetInitialStatefunction

Resets the form back to its initial values and resets validation

additional-buttons

Places additional buttons after the default buttons.

Variables
NameTypeDescription
metaobject

The current validation state of the form.

resetInitialStatefunction

Resets the form back to its initial values and resets validation

form-bottom

Places content below the form and buttons.

Variables
NameTypeDescription
errorsarray

An list of error messages from invalid fields.

metaobject

The current validation state of the form.

setSlotName(field)

Dynamic field created for each field passed in by json. Slot names are generated in `kebab-case`

Variables
NameTypeDescription
fieldunknown

The field object from the list of fields

Events ​

submit

Submit event.

Payload
NameTypeDescription
dataobject

The serialized data from the form by name attribute of each field.

resetFormStatefunction

Convenience method to reset the form state back to clean and allow a subsequent submission.

validated

Emitted after the form validates, without form submission

Payload
NameTypeDescription
validboolean

If the form is valid or not

errorsarray

List of current field errors

Methods ​

NameDescription
hasError

Returns a boolean for if the form is currently showing invalid.

validate

Dynamically validate the form.

submitForm

Used to dynamically submit the form, usually from another component using a ref to this component.

resetFormState

Resets the validation state of the form, useful for creating a fresh set of validation flags.

resetInitialState

Resets the validation state of the form, useful for creating a fresh set of validation flags.

setErrors

Sets field error messages based on key value pairs of field name and array of string error messages.

Examples ​

Using an external submit button ​

Exposing form state ​

The same gate works inside a modal: the buttons slot exposes the same meta, so :disabled="!meta.valid" on EnButtonSubmit keeps the confirm button disabled until the form is valid. The EnModal page shows the full arrangement, with the form's inModal prop placing the buttons in the modal footer.

Creating field layouts ​

The fields slot sits in a flex-row, so col-* classes on the groups lay them out as a grid. That row carries a negative side margin that only a col-* child cancels. For a form that lays its own rows out — inline form groups, a CSS grid, fields wrapped in sections — set :grid-fields="false" so the groups sit inside their container rather than 15px outside it. horizontal is not the way to avoid the row: it swaps in the horizontal form-group styles, which carry the same margin.

Horizontal form layout ​

Although we are trying to stay away from using this layout, there may be a need to still use it.

Easiest option is to pass down the labelClass and inputClass from the EnForm props using the slot variable within the fields slot. The below example just uses the preset defaults that EnForm has.