getBoundElement()
Returns the outermost DOM node attached to the field that was in error. If the field in error
Return=
FieldErrorContext.
getBoundElement()
Return Value
Return—outermost browser DOM node for the field that was in error, for the default View.
If the field is not in the layout and or not in the default view, it returns null
.
Description
The getBoundElement() function makes it possible to access the underlying DOM nodes for Uniface fields. Using the returned DOM node, you can find out what the parent or sibling nodes are so that you can, for example apply error classes.
Important: To make changes to a DOM element that is bound to Uniface objects, use only the Uniface JavaScript data accessing APIs. Do not try to manipulate DOM nodes directly.
Changing Error Reporting
The following example changes the default reporting of server-side validation errors. When the server encounters a validation error, it returns a response with the error information, then webtrigger showError
is fired. By default, Uniface sets an error class on the element bound to the field that is in error, and CSS can be used to style it appropriately.
The following code overwrites the default behavior and sets the error class to the parent element of the element bound to the field:
webtrigger showError javascript // Get bound element of field in error var fieldElement = this.getBoundElement(); // Get parent of element var parentEl = fieldEl.parentElement; // Set error class on parent element instead of the field element itself parentEl.classList.add("-highlight-error-"); // Prevent default error reporting return false; endjavascript end