updating form elements

This commit is contained in:
rolux 2011-12-30 15:03:01 +05:30
commit 73f1105692
13 changed files with 305 additions and 140 deletions

View file

@ -7,6 +7,7 @@ Ox.ObjectInput = function(options, self) {
.defaults({
elements: [],
labelWidth: 128,
value: {},
width: 256
})
.options(options || {})
@ -16,6 +17,12 @@ Ox.ObjectInput = function(options, self) {
height: self.options.elements.length * 24 - 8 + 'px'
});
if (Ox.isEmpty(self.options.value)) {
self.options.value = getValue();
} else {
setValue(self.options.value);
}
self.options.elements.forEach(function($element) {
$element.options({
labelWidth: self.options.labelWidth,
@ -23,10 +30,7 @@ Ox.ObjectInput = function(options, self) {
})
.bindEvent({
change: function(data) {
self.options.value = {};
self.options.elements.forEach(function(element) {
self.options.value[element.options('id')] = element.value();
});
self.options.value = getValue();
that.triggerEvent('change', {
value: self.options.value
});
@ -35,9 +39,23 @@ Ox.ObjectInput = function(options, self) {
.appendTo(that);
});
function getValue() {
var value = {};
self.options.elements.forEach(function(element) {
value[element.options('id')] = element.value();
});
return value;
}
function setValue(value) {
self.options.elements.forEach(function(element) {
element.value(value[element.options('id')]);
});
}
self.setOption = function(key, value) {
if (key == 'value') {
// ...
setValue(value);
}
};