From 4bb3196c03563ed35f548bbacef8be6d18585b45 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Wed, 2 Nov 2011 17:27:20 +0000 Subject: [PATCH] fix form validation bug --- source/Ox.UI/js/Form/Ox.Form.js | 20 +++++++++++++------ .../Ox.UI/js/Video/Ox.BlockVideoTimeline.js | 2 -- source/Ox/js/String.js | 3 +-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/source/Ox.UI/js/Form/Ox.Form.js b/source/Ox.UI/js/Form/Ox.Form.js index 191d2abe..b7c61c0f 100644 --- a/source/Ox.UI/js/Form/Ox.Form.js +++ b/source/Ox.UI/js/Form/Ox.Form.js @@ -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); }; diff --git a/source/Ox.UI/js/Video/Ox.BlockVideoTimeline.js b/source/Ox.UI/js/Video/Ox.BlockVideoTimeline.js index e4d60780..9d447c29 100644 --- a/source/Ox.UI/js/Video/Ox.BlockVideoTimeline.js +++ b/source/Ox.UI/js/Video/Ox.BlockVideoTimeline.js @@ -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]); } diff --git a/source/Ox/js/String.js b/source/Ox/js/String.js index 6365404a..0efc270f 100644 --- a/source/Ox/js/String.js +++ b/source/Ox/js/String.js @@ -71,10 +71,9 @@ Ox.isValidEmail 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 Pad a string to a given length