On 2/12/07, Jörn Zaefferer <[EMAIL PROTECTED]> wrote:

Implementing multiple messages per rule via plugin settings should be
pretty straight forward, but not via the other mechanisms (title
attribute, error labels in markup).


Perhaps the Metadata plugin would help here?? I'm thinking of something
along the lines of

<input type="text" id="email" name="email"
class="{required:true,email:true,messages:{required:'Please
enter your email address',email:'Your email address is not properly
formatted. It should look like [EMAIL PROTECTED]'}}">

The only problem is that it could get messy with all those error messages in
there (and I don't know if the spaces in the error messages will cause any
problems or not).

Speaking of metadata, you may want to consider sectioning off the metadata
that your plugin uses from any other metadata an element might have. For
example, my upcoming New Window plugin (unobtrusively alters selected links
so that they open in new windows) can take advantage of the Metadata plugin
(if it's available and the developer wants to use it), but assumes that
anything that it wants is located in a newWindow object.

<a href="http://www.jquery.com"; class="newWindow
{happy:'happy',joy:'joy',newWindow:features:{width:500,height:300,resizeable:1}}">jQuery</a>

happy and joy will be ignored (since New Window neither knows nor cares what
they are), and only newWindow will be used by my New Window plugin. Yours
could look something like

<input type="text" id="email" name="email"
class="{validate:{rules:{required:true,email:true},messages:{required:'Please
enter your email address',email:'Your email address is not properly
formatted. It should look like [EMAIL PROTECTED]'}}}">

As far as reducing the reliance on IDs (which I've heard mentioned here, and
would make it a lot easier to use this plugin alongside server-side
validation pacakages), you could start by having the keys in the "rules" and
"messages" options be input names instead of IDs. You could then use
something like this (untested) to get the element's ID when necessary:

function getElementId(element) {
   var id = ( /radio|checkbox/i.test(element.type) ) ? element.name :
element.id;

   if(!id) {
       // Element is not a radio button or checkbox and does not have an id
attribute
       id = <generate an ID for this element>;
       element.id = id;
   }

   return id;
}

--
Aaron Heimlich
Web Developer
[EMAIL PROTECTED]
http://aheimlich.freepgs.com
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to