displayError
Manually displays an error message, either inline next to a field or
as a modal, using the same rendering path validation errors use
internally.
Returns: void
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
details | any | required | - | Error display options: message, target element, display type ('inline' | 'modal'), and duration. |
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.
Last updated on