forked from 0x2620/oxjs
updating form elements
This commit is contained in:
parent
8550cc8442
commit
73f1105692
13 changed files with 305 additions and 140 deletions
|
|
@ -10,7 +10,7 @@ Ox.SelectInput = function(options, self) {
|
|||
label: '',
|
||||
labelWidth: 128,
|
||||
max: 1,
|
||||
min: 1,
|
||||
min: 0,
|
||||
placeholder: '',
|
||||
title: '',
|
||||
value: options.max == 1 ? '' : [],
|
||||
|
|
@ -27,28 +27,14 @@ Ox.SelectInput = function(options, self) {
|
|||
labelWidth: self.options.labelWidth,
|
||||
max: self.options.max,
|
||||
min: self.options.min,
|
||||
title: self.options.title,
|
||||
title: getTitle(),
|
||||
value: self.options.value,
|
||||
width: self.options.width
|
||||
})
|
||||
.bindEvent({
|
||||
change: function(data) {
|
||||
if (self.options.title) {
|
||||
self.$select.options({
|
||||
title: Ox.getObjectById(self.options.items, data.value).title
|
||||
});
|
||||
}
|
||||
if (data.value != self.other) {
|
||||
self.$select.options({width: self.options.width})
|
||||
.removeClass('OxOverlapRight')
|
||||
self.$input.hide();
|
||||
self.options.value = data.value
|
||||
} else {
|
||||
self.$select.options({width: self.otherWidth})
|
||||
.addClass('OxOverlapRight');
|
||||
self.$input.show().focusInput(true);
|
||||
self.options.value = self.$input.value();
|
||||
}
|
||||
self.options.value = getValue();
|
||||
setValue(self.isOther);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -63,11 +49,14 @@ Ox.SelectInput = function(options, self) {
|
|||
})
|
||||
.hide();
|
||||
|
||||
setValue();
|
||||
|
||||
that = Ox.FormElementGroup({
|
||||
elements: [
|
||||
self.$select,
|
||||
self.$input
|
||||
],
|
||||
id: self.options.id,
|
||||
join: function(value) {
|
||||
return value[value[0] == self.other ? 1 : 0]
|
||||
},
|
||||
|
|
@ -79,8 +68,62 @@ Ox.SelectInput = function(options, self) {
|
|||
width: self.options.width
|
||||
});
|
||||
|
||||
function getTitle() {
|
||||
var value = self.$select ? self.$select.value() : self.options.value;
|
||||
return Ox.isEmpty(value)
|
||||
? self.options.title
|
||||
: Ox.getObjectById(self.options.items, value).title;
|
||||
}
|
||||
|
||||
function getValue() {
|
||||
self.isOther = self.$select.value() == self.other;
|
||||
return !self.isOther ? self.$select.value() : self.$input.value();
|
||||
}
|
||||
|
||||
function setValue(isOther) {
|
||||
Ox.print('SET VALUE', isOther)
|
||||
if (
|
||||
(!self.options.value && isOther !== true)
|
||||
|| Ox.map(self.options.items, function(item) {
|
||||
return item.id != self.other ? item.id : null;
|
||||
}).indexOf(self.options.value) > -1
|
||||
) {
|
||||
self.$select.options({
|
||||
title: !self.options.value
|
||||
? self.options.title
|
||||
: Ox.getObjectById(self.options.items, self.options.value).title,
|
||||
value: self.options.value,
|
||||
width: self.options.width
|
||||
})
|
||||
.removeClass('OxOverlapRight');
|
||||
self.$input.hide().value('');
|
||||
} else {
|
||||
self.$select.options({
|
||||
title: Ox.getObjectById(self.options.items, self.other).title,
|
||||
value: self.other,
|
||||
width: self.otherWidth
|
||||
})
|
||||
.addClass('OxOverlapRight');
|
||||
self.$input.show().value(self.options.value);
|
||||
}
|
||||
self.$select.options({title: getTitle()});
|
||||
}
|
||||
|
||||
self.setOption = function(key, value) {
|
||||
// ...
|
||||
if (key == 'value') {
|
||||
setValue();
|
||||
}
|
||||
};
|
||||
|
||||
that.value = function() {
|
||||
if (arguments.length == 0) {
|
||||
return getValue();
|
||||
} else {
|
||||
self.options.value = arguments[0];
|
||||
Ox.print('SOV:::', self.options.value)
|
||||
setValue();
|
||||
return that;
|
||||
}
|
||||
};
|
||||
|
||||
return that;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue