webtrigger clearError

The clearError web trigger is used to reset the custom reporting added in the showError trigger for a reported validation error.

Declaration:

webtrigger clearError
javascript
Your JavaScript code here
endjavascript
end

Parameters:

None

Applies to:

All DSP fields

Activation:

Activated when a data update occurs after the showError has been fired.

Default behavior:

If default error styling was applied to the field, the styling is removed.

Behavior upon completion:

None

Return Values

Return value is not used.

Description

Use the clearError trigger to clear the error and reverse the effects applied by the showError web trigger on the same field.

A server-side validation error can only be truly resolved by updating the data and validating it again. However, the error can be cleared on the browser simply by changing the value. This makes the error no longer valid until it is again submitted to the server.

Once the errors are no longer valid, the client needs to be able to clear the errors and error reporting.

When the clearError trigger is fired, it:

  • Should explicitly clear the custom reporting in that was added in the showError trigger.
  • Will implicitly clear the uniface.validationError object.
  • Will implicitly clear the default error styling, if it was applied.

Note: The showError and clearError triggers cannot be used to activate operations on the server. This will result in a uniface.UnifaceError exception. If your own code does not catch this exception, Uniface displays the resulting uniface.UserFunctionError in a message window.

Trigger Activation

The clearError is fired when a data update occurs after the showError has been fired. Data updates make the previous error invalid and can occur when:

  • The field's data is updated on the client, by user interaction or by the setValue API (on the uniface.Field.
  • The field is updated by the server before it returns the response to the browser.
  • The occurrence is removed, either in the client by the remove() and discard() APIs on the uniface.Occurrence object, or on the server by occurrence related statements such as remocc, reconnect, and discard.

Addressing the Error Field in JavaScript

When used in the trigger, the JavaScript this refers to the uniface.FieldErrorContext object rather than the uniface.Field object. This object provides a number of functions for accessing the field that was in error, the DOM node the represents the field in the layout, and the validation error itself.

This ensures that even if the field was removed during the update, it is still possible to clear the error that it caused.

webtrigger clearError

webtrigger clearError
  javascript
    // this = the FieldErrorContext object for the error 
    // get the field that was in error 
	var errorField = this.getField()

    // if the field is present in the layout ...
    if (errorField) {
      // clear the properties that were set in showError
      errorField.clearProperty("style:color");
      errorField.clearProperty("html:title");
    }
  endjavascript
end		

Related Topics