Author: michiel
Date: 2009-05-28 22:31:17 +0200 (Thu, 28 May 2009)
New Revision: 35490
Modified:
mmbase/trunk/html/mmbase/validation/Widgets.js
Log:
added the possibility for options
Modified: mmbase/trunk/html/mmbase/validation/Widgets.js
===================================================================
--- mmbase/trunk/html/mmbase/validation/Widgets.js 2009-05-28 19:57:39 UTC
(rev 35489)
+++ mmbase/trunk/html/mmbase/validation/Widgets.js 2009-05-28 20:31:17 UTC
(rev 35490)
@@ -309,7 +309,8 @@
}
-Widgets.prototype.labelsToInputs = function(selector) {
+Widgets.prototype.labelsToInputs = function(selector, options) {
+ var emptyisuntouched = options['emptyisuntouched'];
$(document).ready(function() {
$(selector).each(function() {
var labelText = $(this).text();
@@ -322,17 +323,41 @@
input.attr("type", "text");
input.addClass("password");
}
+ $(this).css("display", "none");
+ input.focus(function() {
+ // if entered for the first time, remove the label value
+ if ($(this).hasClass("untouched")) {
+ if (emptyisuntouched) {
+ $(this).removeClass("untouched");
+ }
+ this.value = "";
+ if ($(this).hasClass("password")) {
+ $(this).attr("type", "password");
+ }
+ };
+ });
+ input.blur(function() {
+ // if leaving, the value is empty, and empty is equivalent
to 'untouched', put the label back in.
+ if ($(this).val() == "") {
+ if (emptyisuntouched) {
+ $(this).addClass("untouched");
+ }
+ if ($(this).hasClass("untouched")) {
+ $(this).val(labelText);
+ if ($(this).hasClass("password")) {
+ $(this).attr("type", "text");
+ }
+ }
+ }
+ });
+ if (! emptyisuntouched) {
+ input.keyup(function() {
+ $(this).removeClass("untouched");
+ });
+ }
+ } else {
+ // value is not empty, so cant use it for the label
}
- $(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