onAttributeID_(id)()

onAttributeID_(id)()

Replace (id) with the actual ID of the attribute in the current configuration. This function is executed when an attribute is validated because it matches the attribute with (id). For example, use the function name onAttributeID_5 if you want the function to execute when an attribute is validated with the attribute that has an ID of 5 in the configuration. (New v12.0012)

Example:

This example generates an error message when the "style" attribute it used. The "style" attribute has an ID of 125, hence the function name onAttributeID_125().

function onAttributeID_125() {
 Message(1,MSG_ERROR,'Do not use the "'+CurrentAttName+'" attribute.');
}

Example 2:

This example is like the previous example, but there is a limit on how many times the message will be displayed.

function onAttributeID_125() {
 $styleattusederrormsg++;
 if $styleattusederrormsg<4 {
  Message(1,MSG_ERROR,'Do not use the "'+CurrentAttName+'" attribute. This messages is displayed up to 3 times.');
 }
}

Example 3:

This example generates a 'bad attribute value' error message if a "class" attribute contains "unwantedclass". The "class" attribute has an ID of 124, hence the function name onAttributeID_124().

function onAttributeID_124() {
 if getStringStartIndex(CurrentAttValue,"unwantedclass")>=0 {
  Message(1,MSG_ERROR,"Bad attribute value.",getAttValueLocation(CurrentAttIndex));
 }
}

Example 4:

This example saves "href" links (the ID of "href" is 1) that end in "-element" to an array, then writes the links to the file t:\writelinkarray.txt when the validation is complete. This can be useful if you want to extract certain links from a document.

function onAttributeID_1() {
 if endsWithCase(CurrentAttValue,"-element") { // only links that end in "-element"
  // the following only adds the link if it's not already in the array
  if array_search($whatwglinkarray,CurrentAttValue)==-1 {
   $writelinkarray[]=CurrentAttValue; // append the link to the array
  }
 }
}

 
function onEndedValidation() {
 writeFile("t:\writelinkarray.txt",$writelinkarray);
}