Skip to Content
NFSFU234FormValidation v3 is here — file upload validation, config-driven rules, and more.
v2 (legacy)displayError

displayError

The displayError function is used to display error messages in either an inline or modal format. It allows specifying the duration for which the error message should be visible and associates the error message with a specific HTML element.

Works in: HTML5, React JS

ParameterTypeDefaultDescription
detailsObjectundefinedThe details of the error message to be displayed.
details.typestringundefinedThe type of error display (either “inline” or “modal”).
details.messagestringundefinedThe error message to be displayed.
details.durationnumberundefinedThe duration (in milliseconds) for which the error message should be visible.
details.elementHTMLInputElement | HTMLSelectElement | HTMLTextAreaElementundefinedThe HTML element to which the error message is associated.
details.successbooleanfalseA flag indicating whether the operation was successful. Default is false.

Usage

Example: Display Error Message

const errorDetails = { type: 'modal', // or inline message: 'Hello World👋', duration: 5000, element: document.getElementById('myFormId'), // could also be an HTML input element success: false // or true }; nfsfu234FormValidation.displayError(errorDetails);

Example Form HTML

<form id="myFormId"> <input type="text" name="fieldName1" value="value1" data-attr-name="fieldName1" /> <input type="text" name="fieldName2" value="value2" data-attr-name="fieldName2" /> <button type="submit">Submit</button> </form>

JavaScript to Display Error Message

const errorDetails = { type: 'modal', message: 'Hello World👋', duration: 5000, element: document.getElementById('myFormId'), success: false }; nfsfu234FormValidation.displayError(errorDetails);

Expected Output

An error message “Hello World👋” will be displayed as a modal for 5000 milliseconds (5 seconds) associated with the specified form element.

See also

Last updated on