forked from 0x2620/oxjs
form elements rewrite, part 1
This commit is contained in:
parent
cf567e5608
commit
7f83cd3141
30 changed files with 1061 additions and 958 deletions
|
|
@ -24,17 +24,25 @@ Ox.FormElementGroup = function(options, self) {
|
|||
id: '',
|
||||
elements: [],
|
||||
float: 'left',
|
||||
joinValues: null,
|
||||
join: null,
|
||||
separators: [],
|
||||
split: null,
|
||||
value: options.split ? '' : [],
|
||||
width: 0
|
||||
})
|
||||
.options(options || {})
|
||||
.addClass('OxInputGroup');
|
||||
|
||||
if (Ox.isEmpty(self.options.value)) {
|
||||
self.options.value = getValue();
|
||||
} else {
|
||||
setValue();
|
||||
}
|
||||
|
||||
(
|
||||
self.options.float == 'left' ?
|
||||
self.options.elements : Ox.clone(self.options.elements).reverse()
|
||||
).forEach(function($element, i) {
|
||||
).forEach(function($element) {
|
||||
$element.css({
|
||||
float: self.options.float // fixme: make this a class
|
||||
})
|
||||
|
|
@ -42,12 +50,8 @@ Ox.FormElementGroup = function(options, self) {
|
|||
autovalidate: function(data) {
|
||||
that.triggerEvent({autovalidate: data});
|
||||
},
|
||||
change: function(data) {
|
||||
that.triggerEvent({change: {value: that.value()}});
|
||||
},
|
||||
submit: function(data) {
|
||||
that.triggerEvent({change: {value: that.value()}});
|
||||
},
|
||||
change: change,
|
||||
submit: change,
|
||||
validate: function(data) {
|
||||
that.triggerEvent({validate: data});
|
||||
}
|
||||
|
|
@ -55,6 +59,13 @@ Ox.FormElementGroup = function(options, self) {
|
|||
.appendTo(that);
|
||||
});
|
||||
|
||||
function change(data) {
|
||||
self.options.value = getValue();
|
||||
that.triggerEvent('change', {
|
||||
value: self.options.value
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
if (self.options.width) {
|
||||
setWidths();
|
||||
|
|
@ -66,16 +77,34 @@ Ox.FormElementGroup = function(options, self) {
|
|||
});
|
||||
*/
|
||||
|
||||
function getValue() {
|
||||
var value = self.options.elements.map(function($element) {
|
||||
return $element.options('value');
|
||||
});
|
||||
return self.options.join ? self.options.join(value) : value;
|
||||
}
|
||||
|
||||
function getWidth() {
|
||||
|
||||
}
|
||||
|
||||
function setValue() {
|
||||
var values = self.options.split
|
||||
? self.options.split(self.options.value)
|
||||
: self.options.value;
|
||||
values.forEach(function(value, i) {
|
||||
self.options.elements[i].options({value: value});
|
||||
});
|
||||
}
|
||||
|
||||
function setWidth() {
|
||||
|
||||
}
|
||||
|
||||
self.setOption = function(key, value) {
|
||||
|
||||
if (key == 'value') {
|
||||
setValue();
|
||||
}
|
||||
};
|
||||
|
||||
that.replaceElement = function(pos, element) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue