From 5a96969efd8d043bed1ea59402094191cd4a665a Mon Sep 17 00:00:00 2001 From: Rolux Date: Sat, 20 Feb 2010 16:35:58 +0530 Subject: [PATCH] improving labels and placeholders --- build/js/ox.ui.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/build/js/ox.ui.js b/build/js/ox.ui.js index 250af1a8..ff46832f 100644 --- a/build/js/ox.ui.js +++ b/build/js/ox.ui.js @@ -1700,7 +1700,6 @@ requires self.options.type == "textarea" ? "textarea" : "input", self ) .attr({ - placeholder: self.placeholder, type: self.options.type == "textarea" ? null : self.options.type }) .addClass( @@ -1712,6 +1711,8 @@ requires .change(change) .appendTo(that); + self.options.placeholder && that.$input.val(self.option); + if (self.options.clear) { that.$clear = new Ox.Button({ style: "symbol", @@ -1759,9 +1760,21 @@ requires callback(items); } + function blur() { + that.loseFocus(); + if (self.options.placeholder && that.$input.val() === "") { + that.$input.addClass("OxPlaceholder").val(self.option); + } + if (self.options.autocomplete) { + $document.unbind("keydown", keypress); + $document.unbind("keypress", keypress); + } + } + function call() { var value = that.$input.val(); if (self.options.autocomplete) { + //Ox.print("###", self.option, value, callback) Ox.isFunction(self.options.autocomplete) ? ( self.option ? self.options.autocomplete(self.option, value, callback) : @@ -1800,21 +1813,15 @@ requires that.$input.blur(); } - function clear() { - that.$input.val("").focus(); - //call(); - } - function change(event, data) { + self.option = data.value; // fixme: could be "title" as well if (self.options.label) { - self.label = data.value; // fixme: could be "title" as well - that.$label.html(self.label); + that.$label.html(self.option); that.$input.focus(); call(); } else { - self.placeholder = data.value; // fixme: could be "title" as well if (that.$input.is(".OxPlaceholder")) { - that.$input.val(self.placeholder); + that.$input.val(self.option); //that.$input.focus(); } else { that.$input.focus(); @@ -1823,15 +1830,9 @@ requires } } - function blur() { - that.loseFocus(); - if (that.$input.val() === "") { - that.$input.addClass("OxPlaceholder").val(that.$input.attr("placeholder")); - } - if (self.options.autocomplete) { - $document.unbind("keydown", keypress); - $document.unbind("keypress", keypress); - } + function clear() { + that.$input.val("").focus(); + //call(); } function focus() {