wwBusinessObject::AddValidationError

Adds a validation error to the oValidationErrors collection. Pass an error string and optional object name.

The object name can optionally be used to provide direct error link in Web Pages of the page framework.

o.AddValidationError(lcMessage,lcObjectName)

Parameters

lcMessage
An error message.

lcObjectName
Optional - name of a control on a form that this error should be associated with if any. Used by the Page framework optionally to link to the item that has the error.

Example

*** Demonstrates how to use Validation in the Validate
*** method of a business object

* wwDevRegistry :: Validate
LOCAL loDev

loDev = THIS.oData

this.cErrorMsg = ""
this.oValidationerrors.Clear()

IF EMPTY(loDev.Company)
   this.AddValidationerror("A company name is required.","txtCompany")
ENDIF
IF EMPTY(loDev.Name)
   this.AddValidationError("A contact name is required.","txtName")
ENDIF
IF LEN(loDev.Services) < 200
   this.AddValidationError("The service description is too short. At least 200 characters are required.","txtServices")
ENDIF

IF this.oValidationErrors.Count > 0
	THIS.SetError(this.oValidationErrors.ToString())
	RETURN .F.
ENDIF

RETURN .T.

***
*** And here is a way you might use it in a WebControl Page
***

* EditDeveloper_page :: btnSubmit_Click
FUNCTION btnSubmit_Click()

*** Unbind the data back into the control source for this ID
this.UnbindData()

IF !this.oDeveloper.Validate()
   this.AddValidationErrorsToBindingErrors(;
              this.oDeveloper.oValidationErrors)
ENDIF

IF THIS.BindingErrors.Count > 0
   this.ErrorDisplay.Text = this.BindingErrors.ToHtml()   
   RETURN
ENDIF


*** If we get here there are no errors
IF !this.oDeveloper.Save()
   this.ErrorDisplay.Text = this.oDeveloper.cErrorMsg
   RETURN
ENDIF

this.ErrorDisplay.ShowMessage("Developer Entry Saved")
ENDFUNC
*  editDeveloper_Page :: btnSubmit_Click

See also:

Class wwBusinessObject

© West Wind Technologies, 2023 • Updated: 02/17/19
Comment or report problem with topic