[Jifty-commit] r1624 - jifty/trunk/share/web/static/js
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Wed Jul 19 17:41:52 EDT 2006
Author: nelhage
Date: Wed Jul 19 17:41:51 2006
New Revision: 1624
Modified:
jifty/trunk/share/web/static/js/jifty.js
Log:
Not submitting placeholder values when we submit forms or AJAX
Modified: jifty/trunk/share/web/static/js/jifty.js
==============================================================================
--- jifty/trunk/share/web/static/js/jifty.js (original)
+++ jifty/trunk/share/web/static/js/jifty.js Wed Jul 19 17:41:51 2006
@@ -114,7 +114,8 @@
var f = fields[i];
if ( (Form.Element.getType(f) != "registration")
- && (Form.Element.getValue(f) != null)) {
+ && (Form.Element.getValue(f) != null)
+ && (!Jifty.Placeholder.hasPlaceholder(f))) {
if (! a['fields'][Form.Element.getField(f)])
a['fields'][Form.Element.getField(f)] = {};
var field = Form.Element.getField(f);
@@ -235,6 +236,13 @@
}
return elements;
+ },
+
+ clearPlaceholders: function(element) {
+ var elements = Form.getElements(element);
+ for(var i = 0; i < elements.length; i++) {
+ Jifty.Placeholder.clearPlaceholder(elements[i]);
+ }
}
});
@@ -366,7 +374,7 @@
extras.push(e);
}
return extras;
- }
+ },
});
@@ -907,6 +915,14 @@
Event.observe(element, 'focus', this.onFocus.bind(this));
Event.observe(element, 'blur', this.onBlur.bind(this));
this.onBlur();
+
+ var form = Form.Element.getForm(element);
+
+ if(!form.hasPlaceholders) {
+ form.hasPlaceholders = true;
+ Event.observe(form, 'submit',
+ function () { Form.clearPlaceholders(form); } );
+ }
},
onBlur: function() {
@@ -917,12 +933,24 @@
},
onFocus: function() {
- if(Element.hasClassName(this.element, 'placeholder')) {
- this.element.value = '';
- Element.removeClassName(this.element, 'placeholder');
- }
+ Jifty.Placeholder.clearPlaceholder(this.element);
+ },
+
+});
+
+Object.extend(Jifty.Placeholder, {
+
+ hasPlaceholder: function(elt) {
+ return Element.hasClassName(elt, 'placeholder');
+ },
+
+ clearPlaceholder: function(elt) {
+ if(Jifty.Placeholder.hasPlaceholder(elt)) {
+ elt.value = '';
+ Element.removeClassName(elt, 'placeholder');
+ }
}
-
+
});
More information about the Jifty-commit
mailing list