Note that there are some explanatory texts on larger screens.

plurals
  1. POExtending XHTML
    text
    copied!<p>I'm playing around with writing a jQuery plugin that uses an attribute to define form validation behavior (yes, I'm aware there's already a validation plugin; this is as much a learning exercise as something I'll be using). Ideally, I'd like to have something like this:</p> <p>Example 1 - input:</p> <pre><code>&lt;input id="name" type="text" v:onvalidate="return this.value.length &gt; 0;" /&gt; </code></pre> <p>Example 2 - wrapper:</p> <pre><code>&lt;div v:onvalidate="return $(this).find('[value]').length &gt; 0;"&gt; &lt;input id="field1" type="text" /&gt; &lt;input id="field2" type="text" /&gt; &lt;input id="field3" type="text" /&gt; &lt;/div&gt; </code></pre> <p>Example 3 - predefined:</p> <pre><code>&lt;input id="name" type="text" v:validation="not empty" /&gt; </code></pre> <p>The goal here is to allow my jQuery code to figure out which elements need to be validated (this is already done) and still have the markup be valid XHTML, which is what I'm having a problem with. I'm fairly sure this will require a combination of both DTD and XML Schema, but I'm not really quite sure how exactly to execute.</p> <p>Based on <a href="http://www.w3.org/TR/xhtml-modularization/dtd_developing.html#s_dev_attrs" rel="nofollow noreferrer">this article</a>, I've created the following DTD:</p> <pre><code>&lt;!ENTITY % XHTML1-formvalidation1 PUBLIC "-//W3C//DTD XHTML 1.1 +FormValidation 1.0//EN" "http://new.dandoes.net/DTD/FormValidation1.dtd" &gt; %XHTML1-formvalidation1; &lt;!ENTITY % Inlspecial.extra "%div.qname; " &gt; &lt;!ENTITY % xhmtl-model.mod SYSTEM "formvalidation-model-1.mod" &gt; &lt;!ENTITY % xhtml11.dtd PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" &gt; %xhtml11.dtd; </code></pre> <p>And here is "formvalidation-model-1":</p> <pre><code>&lt;!ATTLIST %div.qname; %onvalidation CDATA #IMPLIED %XHTML1-formvalidation1.xmlns.extra.attrib; &gt; </code></pre> <p>I've never done DTD before, so I'm not even really exactly sure what I'm doing. When I run my page through the W3 XHTML validator, I get 80+ errors because it's getting duplicate definitions of all the XHTML elements. Am I at least on the right track? Any suggestions?</p> <hr> <p><strong>EDIT:</strong> I removed this section from my custom DTD, because it turned out that it was actually self-referencing, and the code I got the template from was really for combining two DTDs into one, not appending specific items to one:</p> <pre><code>&lt;!ENTITY % XHTML1-formvalidation1 PUBLIC "-//W3C//DTD XHTML 1.1 +FormValidation 1.0//EN" "http://new.dandoes.net/DTD/FormValidation1.dtd" &gt; %XHTML1-formvalidation1; </code></pre> <p>I also removed this, because it wasn't validating, and didn't seem to be doing anything:</p> <pre><code>&lt;!ENTITY % Inlspecial.extra "%div.qname; " &gt; </code></pre> <p>Additionally, I decided that since I'm only adding a handful of additional items, the separate files model recommended by W3 doesn't really seem that helpful, so I've put everything into the dtd file, the content of which is now this:</p> <pre><code>&lt;!ATTLIST div onvalidate CDATA #IMPLIED&gt; &lt;!ENTITY % xhtml11.dtd PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" &gt; %xhtml11.dtd; </code></pre> <p>So now, I'm not getting any DTD-related validation errors, but the onvalidate attribute still is not valid.</p> <p><strong>Update:</strong> I've ditched the DTD and added a schema: <a href="http://schema.dandoes.net/FormValidation/1.0.xsd" rel="nofollow noreferrer">http://schema.dandoes.net/FormValidation/1.0.xsd</a></p> <p>Using v:onvalidate appears to validate in Visual Studio, but the W3C service still doesn't like it.</p> <p>Here's a page where I'm using it so you can look at the source:</p> <p><a href="http://new.dandoes.net/auth" rel="nofollow noreferrer">http://new.dandoes.net/auth</a></p> <p>And here's the link to the w3c validation result:</p> <p><a href="http://validator.w3.org/check?uri=http://new.dandoes.net/auth&amp;charset=(detect+automatically)&amp;doctype=Inline&amp;group=0" rel="nofollow noreferrer">http://validator.w3.org/check?uri=http://new.dandoes.net/auth&amp;charset=(detect+automatically)&amp;doctype=Inline&amp;group=0</a></p> <p>Is this about as close as I'll be able to get with this, or am I still doing something wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload