Author: michiel
Date: 2009-05-28 17:46:26 +0200 (Thu, 28 May 2009)
New Revision: 35481
Modified:
mmbase/trunk/html/mmbase/validation/Widgets.js
Log:
Added 'labelsToInputs'
Modified: mmbase/trunk/html/mmbase/validation/Widgets.js
===================================================================
--- mmbase/trunk/html/mmbase/validation/Widgets.js 2009-05-28 15:18:15 UTC
(rev 35480)
+++ mmbase/trunk/html/mmbase/validation/Widgets.js 2009-05-28 15:46:26 UTC
(rev 35481)
@@ -8,6 +8,8 @@
* - Widgets.instance.enumerationSuggestion(selector): Makes single
selection only a suggestion, meaning that the value 'OTHER' gives the user the
possibility to type a value herself
* - Widgets.instance.boxes(selector): Makes select into a list of
checkboxes (multiple) or radioboxes (single)
* - Widgets.instance.twoMultiples(selector): Splits up multiple selection
into 2 boxes, the left one containing the selected values, the right one the
optiosn which are not selected.
+
+ * - Widgets.instance.labelsToInputs(selector): Select a bunch of 'labels'.
The text of the label will be put as value of the associated text-input, and
removed on focus. The label itself will be hidden.
*
* @version $Id: Widgets.js,v 1.9 2008-12-30 17:54:06 michiel Exp $ BETA
* @author Michiel Meeuwissen
@@ -304,4 +306,36 @@
});
});
-};
+}
+
+
+Widgets.prototype.labelsToInputs = function(selector) {
+ $(document).ready(function() {
+ $(selector).each(function() {
+ var labelText = $(this).text();
+ var labelFor = $(this).attr("for");
+ var input = $("input[name=" + labelFor + "]");
+ if (input.val() == "") {
+ input.val(labelText);
+ input.addClass("untouched");
+ if (input.attr("type") == 'password') {
+ input.attr("type", "text");
+ input.addClass("password");
+ }
+ }
+ $(this).css("display", "none");
+ input.focus(function() {
+ if ($(this).hasClass("untouched")) {
+ this.value = "";
+ $(this).removeClass("untouched");
+ if ($(this).hasClass("password")) {
+ $(this).attr("type", "password");
+ }
+ };
+ });
+
+ });
+ });
+}
+
+
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs