Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 48167 invoked from network); 18 Feb 2004 20:49:27 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 18 Feb 2004 20:49:27 -0000 Received: (qmail 49558 invoked by uid 500); 18 Feb 2004 20:49:13 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 49501 invoked by uid 500); 18 Feb 2004 20:49:13 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 49487 invoked from network); 18 Feb 2004 20:49:12 -0000 Received: from unknown (HELO wil1rly3.tmcs.net) (209.104.62.3) by daedalus.apache.org with SMTP; 18 Feb 2004 20:49:12 -0000 Received: from pasmail.office.tmcs (pasmail.office.tmcs [172.26.10.131]) by wil1rly3.tmcs.net (8.12.6/8.12.6/200312091159) with ESMTP id i1IKns7d004282 for ; Wed, 18 Feb 2004 12:49:54 -0800 (PST) Received: from [172.26.30.76] (172.26.30.76 [172.26.30.76]) by pasmail.office.tmcs with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id D6P9LTM5; Wed, 18 Feb 2004 12:49:18 -0800 Mime-Version: 1.0 (Apple Message framework v612) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <0FAB7382-6254-11D8-B7D7-000393DC9B06@citysearch.com> Content-Transfer-Encoding: 7bit Cc: toolsdev@citysearch.com From: Masahji Stewart Subject: Javascript Validation Flexibility Date: Wed, 18 Feb 2004 12:50:18 -0800 To: commons-dev@jakarta.apache.org X-Mailer: Apple Mail (2.612) X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N I ran into a roadblock in the validator framework when I wanted to create a custom alert that didn't involve the window popup "alert" function (ie a DHTML implementation). I think it would be extremely useful to allow users to declare their own alert functions that have access to more details about what exactly went wrong in the chain of javascript validation events. So, below I have described a potential solution to this problem that I have tested and verified for backwards compatibility. // first create a custom javascript object that encapsulates the field // information for fields that didn't validate function FieldInfo(name, value, message) { this.name = name; this.value = value; this.message = message; } // declare a variable that acts as a callback to the alert method var alertMethod; // this method captures the current alert functionality (default functionality) var windowAlertMethod = function(fieldInfoArray) { var alertStrings = new Array(); var index = 0; for (i in fieldInfoArray) { alertStrings[index++] = fieldInfoArray[i].message; } alert(alertStrings.join('\n')); } // alertMethod will be windowAlertMethod by default alertMethod = windowAlertMethod; // validate method changes: // All of the validate methods (ie validateRequired, validateMask,..) will have // to take in an extra parameter, the customAlertMethod // // Instead of this: function validateRequired(form) { ... } // This: function validateRequired(form, customAlert) { ... } // All of the methods should create an array of FieldInfo objects instead of // string messages // // Instead of these: fields[i++] = oRequired[x][1]; // These: fields[i++] = new FieldInfo(field.name, field.value, oRequired[x][1]); // Finally, the call to alert will change to the customAlert call // The check provides backwards compatibility with the single parameter // validate method calls, but also allows us to create fully custom grouped // validation methods (like the ones generated in the struts framework) that // call preexisting validate methods // // Instead of this: alert(fields.join('\n')); // This: if(customAlert) { // customAlert(fields); // } else { // alertMethod(fields); // } -masahji --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org