fix form validation bug
This commit is contained in:
parent
be4d7c9124
commit
4bb3196c03
3 changed files with 15 additions and 10 deletions
|
@ -34,10 +34,16 @@ Ox.Form = function(options, self) {
|
|||
itemIsValid: []
|
||||
});
|
||||
|
||||
// fixme: form isn't necessarily empty/invalid
|
||||
self.options.items.forEach(function(item, i) {
|
||||
var validateItem = item.options('validate');
|
||||
if (validateItem) {
|
||||
validateItem(item.value(), function(data) {
|
||||
self.itemIsValid[i] = data.valid;
|
||||
});
|
||||
} else {
|
||||
self.itemIsValid[i] = item.value().length > 0;
|
||||
}
|
||||
self.itemIds[i] = item.options('id') || item.id;
|
||||
self.itemIsValid[i] = !!item.value().length;
|
||||
that.append(self.$items[i] = Ox.FormItem({element: item}));
|
||||
item.bindEvent({
|
||||
/*
|
||||
|
@ -51,7 +57,7 @@ Ox.Form = function(options, self) {
|
|||
},
|
||||
*/
|
||||
autovalidate: function(data) {
|
||||
validate(i, data.valid);
|
||||
validateForm(i, data.valid);
|
||||
data.valid && self.$items[i].setMessage('');
|
||||
},
|
||||
/*
|
||||
|
@ -74,7 +80,7 @@ Ox.Form = function(options, self) {
|
|||
self.formIsValid && that.submit();
|
||||
},
|
||||
validate: function(data) {
|
||||
validate(i, data.valid);
|
||||
validateForm(i, data.valid);
|
||||
// timeout needed for cases where the form is removed
|
||||
// from the DOM, triggering blur of an empty item -
|
||||
// in this case, we don't want the message to appear
|
||||
|
@ -90,13 +96,14 @@ Ox.Form = function(options, self) {
|
|||
}
|
||||
|
||||
function submitCallback(data) {
|
||||
data.forEach(function(v, i) {
|
||||
Ox.forEach(data, function(v, i) {
|
||||
self.$items[getItemIndexById(v.id)].setMessage(v.message);
|
||||
});
|
||||
}
|
||||
|
||||
function validate(pos, valid) {
|
||||
function validateForm(pos, valid) {
|
||||
self.itemIsValid[pos] = valid;
|
||||
Ox.print('VALID???', self.itemIsValid)
|
||||
if (Ox.every(self.itemIsValid) != self.formIsValid) {
|
||||
self.formIsValid = !self.formIsValid;
|
||||
that.triggerEvent('validate', {
|
||||
|
@ -122,6 +129,7 @@ Ox.Form = function(options, self) {
|
|||
}
|
||||
|
||||
that.submit = function() {
|
||||
// fixme: this seems to be unneeded
|
||||
//Ox.print('---- that.values()', that.values())
|
||||
self.options.submit(that.values(), submitCallback);
|
||||
};
|
||||
|
|
|
@ -106,13 +106,11 @@ Ox.BlockVideoTimeline = function(options, self) {
|
|||
// OxTarget and OxSpecialTarget are needed for InfoList
|
||||
.addClass('OxInterface OxTarget OxSpecialTarget')
|
||||
.css({
|
||||
position: 'absolute',
|
||||
top: '2px',
|
||||
width: Math.round(self.options.duration) + 'px',
|
||||
height: '20px',
|
||||
marginLeft: (-i * self.options.width) + 'px',
|
||||
//background: 'rgba(255, 0, 0, 0.1)',
|
||||
zIndex: 11
|
||||
})
|
||||
.appendTo(self.$lines[i]);
|
||||
}
|
||||
|
|
|
@ -71,10 +71,9 @@ Ox.isValidEmail <f> Tests if a string is a valid e-mail address
|
|||
> Ox.isValidEmail("foo@bar..com")
|
||||
false
|
||||
@*/
|
||||
// fixme: rename to isEmail
|
||||
Ox.isValidEmail = function(str) {
|
||||
return !!/^[0-9A-Z\.\+\-_]+@(?:[0-9A-Z\-]+\.)+[A-Z]{2,6}$/i.test(str);
|
||||
}
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.pad <f> Pad a string to a given length
|
||||
|
|
Loading…
Reference in a new issue