Skip to content

EnForm

Preview

Props

NameDescriptionDefaultControl
isSubmitting

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

boolean
false
validateOnMount

Validates form immediately on mount.

boolean
false
horizontal

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

boolean
false
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
displayOnly

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

boolean
false
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."
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
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"
disableSubmit

Disables submit button and form submit event.

boolean
false
disableForm

Disables form and removes submit button.

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
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

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.

inputGroupPropsarray.<object>

The input group props that set layout values for a form group component.

<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

Creating field layouts

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.