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