select input: fix size, keep input value around

This commit is contained in:
rolux 2014-05-18 02:45:34 +02:00
parent c88ce78e32
commit 8c4e7fbe84

View file

@ -11,6 +11,7 @@ Ox.SelectInput = function(options, self) {
var that; var that;
self = Ox.extend(self || {}, { self = Ox.extend(self || {}, {
options: Ox.extend({ options: Ox.extend({
inputValue: '',
inputWidth: 128, inputWidth: 128,
items: [], items: [],
label: '', label: '',
@ -25,7 +26,7 @@ Ox.SelectInput = function(options, self) {
}); });
self.other = self.options.items[self.options.items.length - 1].id; self.other = self.options.items[self.options.items.length - 1].id;
self.otherWidth = self.options.width - self.options.inputWidth - 3; // fixme: 3? obscure! self.otherWidth = self.options.width - self.options.inputWidth;
self.$select = Ox.Select({ self.$select = Ox.Select({
items: self.options.items, items: self.options.items,
@ -46,7 +47,8 @@ Ox.SelectInput = function(options, self) {
self.$input = Ox.Input({ self.$input = Ox.Input({
placeholder: self.options.placeholder, placeholder: self.options.placeholder,
width: 0 width: self.options.inputWidth,
value: self.options.inputValue
}) })
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
@ -114,7 +116,7 @@ Ox.SelectInput = function(options, self) {
width: self.options.width width: self.options.width
}) })
.removeClass('OxOverlapRight'); .removeClass('OxOverlapRight');
self.$input.hide().value(''); self.$input.hide();
} else { } else {
self.$select.options({ self.$select.options({
title: Ox.getObjectById(self.options.items, self.other).title, title: Ox.getObjectById(self.options.items, self.other).title,
@ -122,7 +124,7 @@ Ox.SelectInput = function(options, self) {
width: self.otherWidth width: self.otherWidth
}) })
.addClass('OxOverlapRight'); .addClass('OxOverlapRight');
self.$input.show().value(self.options.value).focusInput(); self.$input.show().focusInput(true);
} }
self.$select.options({title: getTitle()}); self.$select.options({title: getTitle()});
} }