Saving hidden values ​​in HTML (for hints, errors, default values). Recommendations

I just saw this jQuery Metadata Plugin from John Resig, Yehuda Katz, Jarn Zafferer and Paul McLanahan, in my search for JQuery Form Validation and what an interesting idea!

I am wondering what are the general guidelines for storing things like error / validation text, tooltip text, default text, etc. I know that you can put them in the title="My Tooltip Message" attribute, but it would be very dirty and would not be DRY if many of my items had the same tooltips and errors, so to speak.

And is there something wrong with storing all this in hidden inputs or html metadata? Or is there a better way to just save all this in an XML configuration file and get them through jQuery?

+6
jquery html validation configuration
source share
3 answers

HTML5 supports custom attributes, starting with "data-" ex: "data-origvalue" can store the original input value, which can be used later to determine if the user has changed.

JQuery 1.4 now supports this with the .data () functions: http://api.jquery.com/data/

If you are not going to use jQuery, the official recommendation for good practice is to use something like "data-LIBRARYNAME-ATTRNAME" ex: "data-jquery-origvalue", so the two libraries will not conflict. I suggest you follow this and come up with one unique to the LIBRARYNAME part.

+4
source share

Well, I would keep the hints in the "title" tag, given that it is supported for it.

How about other metadata? It depends. Usually I will store them in ready-made properties on the object itself, because this is also supported. To personal preference, though, IMHO. If I didn’t do this, I would save them on some map in the secondary .js file, but that would be unpleasant to manage.

0
source share

You can also save all the things in a JS file, which can be on demand, generated by ASP.NET or PHP, so you will edit all the messages in the format you need, and then simply output them as a js array or something like that.

0
source share

All Articles