Please help me with this custom validation rule

Post here if your topic is about CSS HTML Validator but doesn't fit in another forum.
Post Reply
Anjana P
Rank I - Novice
Posts: 18
Joined: Thu Sep 22, 2011 11:24 pm

Please help me with this custom validation rule

Post by Anjana P »

Hi Albert,

Below is the function that you provided me on one of my previous posts. I modified it to check for unwanted nesting of columnA/columnB/columnC/columnD/columnE within each other. Bascially our coding pattern prohibits nesting these columns within each other.
Below is the code.

1. The trouble I am having is that it works beautifully for columnA and columnB but not for any other of them :(.
2. I think you are using jQuery below which I am not very well familiar with (so trying to read it up). Also, the function names - are these specific to the tool?

function onStartValidation()
{
#indivcount=0;
$divclassarray='';
}

function onStartTag_div()
{
#indivcount++;
// Message (1, MSG_MESSAGE,'<div> level '+$indivcount+'.'); // for testing
if hasAtt("class")
{
#classindex=getAttIndex("class");
$classvalue=getAttValue(#classindex);
// Throw error if columnA is nested under any other column
if (matchNoCase($classvalue,"columnA") || matchNoCase($classvalue,"columnB") || matchNoCase($classvalue,"columnC") || matchNoCase($classvalue,"columnD") || matchNoCase($classvalue,"columnE"))
{
if isValueInArray("divclassarray","columnA")>=0
{
Message(1,MSG_ERROR,'Cannot nest <div class="'+$classvalue+'"> under <div class="columnA">.');
}
if isValueInArray("divclassarray","columnB")>=0
{
Message(1,MSG_ERROR,'Cannot nest <div class="'+$classvalue+'"> under <div class="columnB">.');
}
if isValueInArray("divclassarray","columnC")>=0
{
Message(1,MSG_ERROR,'Cannot nest <div class="'+$classvalue+'"> under <div class="columnC">.');
}
if isValueInArray("divclassarray","columnD")>=0
{
Message(1,MSG_ERROR,'Cannot nest <div class="'+$classvalue+'"> under <div class="columnD">.');
}
if isValueInArray("divclassarray","columnE")>=0
{
Message(1,MSG_ERROR,'Cannot nest <div class="'+$classvalue+'"> under <div class="columnE">.');
}
}
$divclassarray[#indivcount]=$classvalue;
}
}

function onEndTag_div()
{
$divclassarray[#indivcount]='';
#indivcount--;
}

Thanks in Advance!

-Anjana P
Anjana P
Rank I - Novice
Posts: 18
Joined: Thu Sep 22, 2011 11:24 pm

Re: Please help me with this custom validation rule

Post by Anjana P »

Guess what! The function is correct and it worked! I think there is some issue with the tool. The tool somehow did not read the updated .cfg file. I closed the tool, opened it again and re-ran error check - and I got the respective error messages.

Can you please check if this issue is happening at your end too? You could report it as a bug.

-Anjana P
User avatar
Albert Wiersch
Site Admin
Posts: 3785
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Please help me with this custom validation rule

Post by Albert Wiersch »

Anjana P wrote:Guess what! The function is correct and it worked! I think there is some issue with the tool. The tool somehow did not read the updated .cfg file. I closed the tool, opened it again and re-ran error check - and I got the respective error messages.

Can you please check if this issue is happening at your end too? You could report it as a bug.

-Anjana P
Hello, first, to answer a previous question, the "tag name programming language" in CSE HTML Validator is a custom language designed just for CSE HTML Validator.

I'm glad the function is working as expected now. If you change the user function file, then you will need to reload the configuration for the changes to take effect. This causes the config files to be reloaded. I suspect that may have been the issue. If you find out otherwise, then please let me know.

A quick way to reload the configuration files would be Options->Configuration Editor->Load. I hope this helps!
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
Anjana P
Rank I - Novice
Posts: 18
Joined: Thu Sep 22, 2011 11:24 pm

Re: Please help me with this custom validation rule

Post by Anjana P »

Oh Okay. Load it again. Sure, I will give it a try next time.

Can you help me with any tutorials you have (for the above syntax) so that I could understand how to create these functions?
The above function caters to DIV. I might want to create functions for table/span/div with a particular class/etc.

Thanks!
Anjana P
User avatar
Albert Wiersch
Site Admin
Posts: 3785
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Please help me with this custom validation rule

Post by Albert Wiersch »

Anjana P wrote:Can you help me with any tutorials you have (for the above syntax) so that I could understand how to create these functions?
The above function caters to DIV. I might want to create functions for table/span/div with a particular class/etc.
Sure. Please take a look at the documentation. There is a 'Special Functions' topic under 'Reference->Tag Name Programming Language->Function Reference'. In that same section of the documentation are the functions and the syntax of the "tag name programming language" you can use to create your own user functions to add to the user functions file.

Doing something similar for other tags shouldn't be difficult. The function names to use would be like what you are using now, but replace the "_div" part of the function name with something else - like "_table" for table tags, and edit the function accordingly.

I hope this helps.
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
Anjana P
Rank I - Novice
Posts: 18
Joined: Thu Sep 22, 2011 11:24 pm

Re: Please help me with this custom validation rule

Post by Anjana P »

Awesome! I will check it out. Thanks :)

-Anjana P
Post Reply