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)

Attribute IDs (and other IDs) can be found using the Configuration Editor.

Example 1:

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() { // "_125" because 125 is the ID of the "style" attribute
 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() { // "_125" because 125 is the ID of the "style" attribute
 $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() { // "_124" because 124 is the ID of the "class" attribute
 if stripos(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() { // "_1" because 1 is the ID of the "href" attribute
 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);
}

Example 5:

This example generates a warning message if there are leading or trailing white-space characters in the value of the "class" attribute. The "class" attribute has an ID of 124, hence the function name onAttributeID_124().

function onAttributeID_124() { // "_124" because 124 is the ID of the "class" attribute
 if checkString(3,CurrentAttValue) {
  Message(1,MSG_WARNING,'The value for "'+CurrentAttName+'" has leading and/or trailing white-space characters.',getAttValueLocation(CurrentAttIndex));
 }
}