onUnknownAttributeMessage()

onUnknownAttributeMessage()

This function is called when an attribute is unknown and a validator error message is about to be generated; this function can be used to ignore unknown attributes and/or to change or display additional messages when certain unknown attributes are used. The following variables are defined when this function is called and may be modified before the validator message is displayed:

$ouam_attname - the name of the unknown attribute

$ouam_msgtext - the message text of the validator message that will be generated

$ouam_msgtextappend - an additional message that is appended to the end of $ouam_msgtext

$ouam_msgtextprepend - an additional message that is prepended to the front of $ouam_msgtext; the default is an empty string

$ouam_msgcat - the message category (as a string) of the validator message that will be generated

the default is the empty string "" for no category

as of 2019/v19 this can also be set in this function to a category number (integer) in addition to a category string

$ouam_msgflags - the message flags value used when calling MessageEx() to generate the message; set to 0 to cancel the message

$ouam_msgid - the message ID of the validator message that will be generated; the default is -1 for no message ID

$ouam_msgtype - the message type of the validator message that will be generated; the default is $MSG_ERROR

Example 1

This function improves the default error messages for the "aria-role" and "aria-labeledby" attributes by improving the variable $ouam_msgtextappend.

function onUnknownAttributeMessage() {
 if $ouam_attname=="aria-role" {
  $ouam_msgtextappend='Perhaps this attribute should be "role" instead of "'+$ouam_attname+'"?';
 }
 elseif $ouam_attname=="aria-labeledby" {
  $ouam_msgtextappend='Perhaps this attribute should be "label-labelledby"? "'+$ouam_attname+'" is a common misspelling.';
 }
}

Example 2

This example generates a custom error message the first 3 times that the unknown "automationid" attribute is used. No error message will be generated for subsequent uses.

function onUnknownAttributeMessage() {
 if $ouam_attname=="automationid" {
  $ouam_msgflags=0; // cancel default message
  $automationidusedcount++;
  if $automationidusedcount<4 {
   Message(1,MSG_ERROR,'Used the non-standard attribute "'+CurrentAttName+'" attribute.');
}}}