improving labels and placeholders

This commit is contained in:
Rolux 2010-02-20 16:35:58 +05:30
parent 2699634ac9
commit 31f96294aa

View File

@ -1700,7 +1700,6 @@ requires
self.options.type == "textarea" ? "textarea" : "input", self self.options.type == "textarea" ? "textarea" : "input", self
) )
.attr({ .attr({
placeholder: self.placeholder,
type: self.options.type == "textarea" ? null : self.options.type type: self.options.type == "textarea" ? null : self.options.type
}) })
.addClass( .addClass(
@ -1712,6 +1711,8 @@ requires
.change(change) .change(change)
.appendTo(that); .appendTo(that);
self.options.placeholder && that.$input.val(self.option);
if (self.options.clear) { if (self.options.clear) {
that.$clear = new Ox.Button({ that.$clear = new Ox.Button({
style: "symbol", style: "symbol",
@ -1759,9 +1760,21 @@ requires
callback(items); 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() { function call() {
var value = that.$input.val(); var value = that.$input.val();
if (self.options.autocomplete) { if (self.options.autocomplete) {
//Ox.print("###", self.option, value, callback)
Ox.isFunction(self.options.autocomplete) ? ( Ox.isFunction(self.options.autocomplete) ? (
self.option ? self.option ?
self.options.autocomplete(self.option, value, callback) : self.options.autocomplete(self.option, value, callback) :
@ -1800,21 +1813,15 @@ requires
that.$input.blur(); that.$input.blur();
} }
function clear() {
that.$input.val("").focus();
//call();
}
function change(event, data) { function change(event, data) {
self.option = data.value; // fixme: could be "title" as well
if (self.options.label) { if (self.options.label) {
self.label = data.value; // fixme: could be "title" as well that.$label.html(self.option);
that.$label.html(self.label);
that.$input.focus(); that.$input.focus();
call(); call();
} else { } else {
self.placeholder = data.value; // fixme: could be "title" as well
if (that.$input.is(".OxPlaceholder")) { if (that.$input.is(".OxPlaceholder")) {
that.$input.val(self.placeholder); that.$input.val(self.option);
//that.$input.focus(); //that.$input.focus();
} else { } else {
that.$input.focus(); that.$input.focus();
@ -1823,15 +1830,9 @@ requires
} }
} }
function blur() { function clear() {
that.loseFocus(); that.$input.val("").focus();
if (that.$input.val() === "") { //call();
that.$input.addClass("OxPlaceholder").val(that.$input.attr("placeholder"));
}
if (self.options.autocomplete) {
$document.unbind("keydown", keypress);
$document.unbind("keypress", keypress);
}
} }
function focus() { function focus() {