Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing Hidden Values in HTML (for tooltip, error, defaults) Best Practices

I just saw this JQuery Metadata Plugin by John Resig, Yehuda Katz, Jarn Zaefferer, and Paul McLanahan, in my search for JQuery Form Validation, and that's an interesting idea!

I'm wondering what general best practices are for storing things like error/validation text, tooltip text, default value text, etc. I know you can place them into the title="My Tooltip Message" attribute, but that would get very messy and wouldn't be DRY if a lot of my items had the same tooltips and errors so to speak.

So is there anything wrong with storing all of that in either hidden input fields or html metadata? Or is there a better way of just storing it all in an XML config file and getting them out via JQuery?

like image 445
Lance Avatar asked Feb 11 '10 22:02

Lance


1 Answers

HTML5 supports custom attributes starting with "data-" ex: "data-origvalue" could store the original value of an input which could be used later to determine if the user changed it.

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

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

like image 105
Mark Kinsella Avatar answered Oct 25 '22 02:10

Mark Kinsella