1
0
Fork 0
forked from 0x2620/oxjs

form elements rewrite, part 1

This commit is contained in:
rlx 2011-12-21 13:42:47 +00:00
commit 7f83cd3141
30 changed files with 1061 additions and 958 deletions

View file

@ -59,7 +59,7 @@ Ox.ArrayInput = function(options, self) {
.bindEvent({
change: function(data) {
self.options.sort && data.value !== '' && sortInputs();
self.options.value = that.value();
self.options.value = getValue();
that.triggerEvent('change', {
value: self.options.value
});
@ -77,7 +77,7 @@ Ox.ArrayInput = function(options, self) {
var index = $(this).parent().data('index');
if (self.$input[index].value() !== '') {
self.$input[index].options({value: ''});
self.options.value = that.value();
self.options.value = getValue();
that.triggerEvent('change', {
value: self.options.value
});
@ -106,6 +106,13 @@ Ox.ArrayInput = function(options, self) {
updateInputs();
}
function getValue() {
return Ox.map(self.$input, function($input) {
var value = $input.value();
return value === '' ? null : value;
});
};
function removeInput(index) {
Ox.Log('Form', 'remove', index);
[
@ -118,6 +125,18 @@ Ox.ArrayInput = function(options, self) {
updateInputs();
}
function setValue() {
if (self.options.value.length == 0) {
self.options.value = [''];
}
while (self.$input.length) {
removeInput(0);
}
self.options.value.forEach(function(value, i) {
addInput(i, value);
});
}
function setWidths() {
self.$label && self.$label.options({width: self.options.width})
self.$element.forEach(function($element, i) {
@ -151,15 +170,7 @@ Ox.ArrayInput = function(options, self) {
self.setOption = function(key, value) {
if (key == 'value') {
if (self.options.value.length == 0) {
self.options.value = [''];
}
while (self.$input.length) {
removeInput(0);
}
self.options.value.forEach(function(value, i) {
addInput(i, value);
});
setValue();
} else if (key == 'width') {
setWidths();
}
@ -171,16 +182,6 @@ Ox.ArrayInput = function(options, self) {
});
};
// fixme: can't we generally use options.value for this?
that.value = function() {
if (arguments.length == 0) {
return Ox.map(self.$input, function($input) {
var value = $input.value();
return value === '' ? null : value;
});
}
};
return that;
};