Ox.Form: don't pass submit option, trigger submit event

This commit is contained in:
rolux 2012-06-05 11:09:44 +02:00
parent 5a47341367
commit 01587f7348

View file

@ -7,7 +7,6 @@ Ox.Form <f> Form Object
error <s> error
id <s> id
items <a|[]> []
submit <f|null> on submit function
self <o> shared private variable
@*/
@ -19,9 +18,6 @@ Ox.Form = function(options, self) {
error: '',
id: '',
items: [],
// FIXME: don't pass function,
// listen to event instead!
submit: null,
validate: function(valid) {
return Ox.every(valid);
}
@ -43,16 +39,6 @@ Ox.Form = function(options, self) {
self.itemIds[i] = item.options('id') || item.id;
self.$items[i] = Ox.FormItem({element: item}).appendTo(that);
item.bindEvent({
/*
blur: function(data) {
validate(i, data.valid);
if (data.valid) {
self.$messages[i].html('').hide();
} else {
self.$messages[i].html(data.message).show();
}
},
*/
autovalidate: function(data) {
validateForm(i, data.valid);
data.valid && self.$items[i].setMessage('');
@ -97,12 +83,6 @@ Ox.Form = function(options, self) {
return self.itemIds.indexOf(id);
}
function submitCallback(data) {
Ox.forEach(data, function(v) {
self.$items[getItemIndexById(v.id)].setMessage(v.message);
});
}
function validateForm(pos, valid) {
self.itemIsValid[pos] = valid;
if (self.options.validate(self.itemIsValid) != self.formIsValid) {
@ -149,13 +129,17 @@ Ox.Form = function(options, self) {
self.$items.splice(pos, 1);
}
that.setMessages = function(messages) {
Ox.forEach(messages, function(v) {
self.$items[getItemIndexById(v.id)].setMessage(v.message);
});
};
/*@
submit <f> submit
@*/
that.submit = function() {
// fixme: this seems to be unneeded
//Ox.Log('Form', '---- that.values()', that.values())
self.options.submit(that.values(), submitCallback);
that.triggerEvent('submit', {values: that.values()});
};
/*@