wwHtmlHelpers::HtmlErrorDisplay
about 2 minutes to read

Creates an HTML error display 'bar' using the stock bootstrap Alert box that can be easily embedded into a page.

Pass in a message along with an error icon to render the control, or leave the value empty and render nothing. You can also use an HtmlErrorDisplayConfig object instead of passing parameters.

Example with multiple Parameters:

Embedding the control into a template is super easy:

html
<%= HtmlErrorDisplay(pcErrorMessage,"warning") %>

Now if pcErrorMessage is empty nothing renders. But when the value is filled it display an error box:

html
<%= HtmlErrorDisplay(pcErrorMessage,"info", [class="my-css-class"], "Header",.t.) %>

Some of the formats and icons supported are:

  • error, warning, danger
  • info, success

warning is the default and you can use any of the Bootstrap alert styles available.

Example with HtmlErrorDisplayConfig

You can also pass in a HtmlErrorDisplayConfig object instead of individual values:

foxpro
* In Process method: PRIVATE poError poError = CREATEOBJECT("HtmlErrorDisplayConfig") ... logic that deals with input parsing IF llIsValidationError *** Assign properties to the poError object poError.Message = "A validation error occurred..." ENDIF Response.ExpandScript()

Then in the HTML Template:

html
<%= HtmlErrorDisplay(poError) %>
o.HtmlErrorDisplay(lcMessage, lcImage, lcAttributes,  
                   lcHeader, llDismissable)

Return Value

Html string

Parameters

lcMessage
The message to display or an HtmlErrorDisplayConfig object.

lcImage
The image to display in the error bar. Defaults to: ERROR (cannot be left blank) Images use ResolveUrl so you can specify: ~/images/yourimage.gif

lcAttributes
Optional attributes. The default is: [class="errordisplay" style="width: 450px;"]. If you override this parameter make sure that you include the above or alternates to make up for it.

lcHeader
An optional header for the message bar. Displays ontop of the message in bold with a horizontal line separating it from the message.

llDismissable
If .T. shows a close icon on the message box.

Example

foxpro
lcOutput = HtmlErrorDisplay("This is a simple info","info") lcOutput = HtmlErrorDisplay("This is a simple info with dismissable","info",; "","",.T.) lcOutput = HtmlErrorDisplay("This is a simple error with header","info",; "","An error occurred",.T.) lcOutput = HtmlErrorDisplay("This is a simple error with header","info",; "width: 300px","An error occurred",.T.)

A more complete example as part of a form validation operation might look like this:

foxpro
Function TimeReport *** Error display object poError = CREATEOBJECT("HtmlErrorDisplayConfig") *** Business object for binding poReportParms = CREATEOBJECT("ReportParameters") IF (Request.IsPostBack()) *** Assign validation errors poError.Errors = Request.UnbindFormVars(poReportParms) IF (poError.Errors.Count > 0) poError.Message = poError.Errors.ToHtml() poError.Header = "Please fix the following form entry errors" ELSE poError.Message = "Ready to run report." poError.Icon = "info" ENDIF ENDIF *** Display the template Response.ExpandScript(Config.cHtmlPagePath + "TimeReport.ttk")

In the template then:

html
<%= HtmlErrorDisplay(poError) %>

See also:

Class wwHtmlHelpers

© West Wind Technologies, 1996-2024 • Updated: 09/17/16
Comment or report problem with topic