/**
[BSD License. This license contains no advertising clause.]
validate_form.js: A comprehensive solution for validating the most common rules in HTML forms.
http://sourceforge.net/projects/validateformjs
Copyright (C) 2003-2005, Jeff Epstein
All rights reserved.
Modifications: No
Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met:
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* If modifications are made to source code then this license should indicate that fact in the "Modifications" section above.
* Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[NOTE: This license contains NO advertising clause.]
**/
/**
JS FILE OVERVIEW DOCUMENTATION
The heart of the validate_form.js
project, and the only file you need to import (via <SCRIPT SRC="...
).
See the tutorials for implementation details.
**/
//If there are more than v this v number of demo-test-value
//functions, print a drop-down box instead of individual
//buttons.
var iBUTTON_THRESHOLD = 10;
var sDDB_DIVIDER = "[__DDB_DIVIDER__]";
var bDBG_TEST_FUNC_CALLS = false;
var bTST_FUNCS_ELIM_TYPE_POSTS = false;
var bTST_FUNCS_pppp_TO_POINT = false;
var bTST_FUNCS_dddd_TO_DASH = false;
var bTST_FUNCS___TO_SPACE = false;
var bCRSH_ALRT = true;
var bCRSH_DGNSTCS = true;
var bCRSH_THROW = true;
//If this is a 'concept' page, then set this to true.
//
//In the demo testing value buttons/ddb values, the
//'_txt'/'_pwd'/... will be suppressed from displaying. It
//is *assumed* that there is a type prefix, and the last four
//characters are blindly eliminated.
//
//This also changes...
// 'neg' to '-'
// 'neg' is expected to be lowercase, and the first
// three characters. Any other instances are not
// replaced.
// 'p' to '.'
// 'p' is only expected to exist once. Only the first
// 'p' is replaced.
var bCONCEPT_DOC_PAGE = false;
//Truly global among all forms.
var sJSDIR;
var sSifCfgUrl;
var bDbgJSLoads;
var bLDD_VFPD = false;
var bLDD_CIBC = false;
var bLDD_DBG = false;
var bLDD_OD = false;
var bLDD_STASIF = false;
var bLDD_SIF_CFG = false;
var bLDD_CI = false;
var bVFPDInUrl = false;
var aVfbc = [];
var sSifCfgUrl;
var bDbgJSLoads;
var sDMOV_FUNC_PRE = "vfpdtf__";
var sURLP_VFPD = "vfpd";
var sURLP_CIBC = "load_cibc";
var sFRM_NM_VFPD = "form_vfpd__";
var bLVFCalled = false; //XCMAX
/**
PUBLIC FUNCTION
Starts the validate_form.js
loading procedure, as completed by completeVFLoad()
.
Calling rules/sequence: This function must be called before any other functions in the validate_form.js
project, and may only be called once. It must be accompanied by a call to completeVFLoad()
, in the value of the body.onLoad
attribute. After calling this function, you may then call configVF()
and configVFPD()
.
PARAMETERS
Required parameters are detoned by '*'.
Name |
Description |
Values |
s_jsDirUrl * |
The base/relative url to the directory containing all validate_form.js code, including the final slash ('/'). This must be exactly the same as the path to validate_form.js , which is manually imported. |
For example, if the webpage is at
http://www.mywebsite.com/webpages/mywebpage.html
and the validate_form.js directory is
http://www.mywebsite.com/validate_form_js-___RPLC___ vfjs.version ___RPLCZ___
then this parameter should equal
../validate form js-___RPLC___ vfjs.version ___RPLCZ___/ |
s_sifCfgUrl |
The base/relative url from this webpage, to your SIFmt configuration file, defining your sif-attributes. If you have no sif-attributes, set this to undefined . |
See s_jsDirUrl for a url example. |
b_dbgJSLoads |
Pop an alert() box for each JavaScript file loaded by the client? This can give you a sense of how much client download there is, depending on the validate_form.js features you use. |
true : An alert box is launched each time a JavaScript file is loaded to memory.
false : File loading is silent. When not provided, it defaults to false .
|
SIGNATURE
loadVF(s_jsDirUrl, s_sifCfgUrl, b_dbgJSLoads)
**/
function loadVF(s_jsDirUrl, s_sifCfgUrl, b_dbgJSLoads) {
if(bLVFCalled) { //XCMAX
crsh("vf.lvf1", loadVF, "loadVF (XCMAX): This function was already called.");
} //XCMAX
bLVFCalled = true; //XCMAX
ciMissing(loadVF, "loadVF (XCMAX)", "s_jsDirUrl", s_jsDirUrl);
if(s_jsDirUrl.substring((s_jsDirUrl.length - 1), s_jsDirUrl.length) != "/") { //XCMAX
crsh("vf.lvf1", loadVF, "loadVF (XCMAX): s_jsDirUrl must end with a url slash ('/'). Currently '" + s_jsDirUrl + "'.");
} //XCMAX
sJSDIR = s_jsDirUrl;
sSifCfgUrl = s_sifCfgUrl;
bDbgJSLoads = (df(b_dbgJSLoads) && b_dbgJSLoads);
if(df(sSifCfgUrl)) {
loadJS(bLDD_STASIF, true, sJSDIR, "vf_stASIF.js");
//false: It always needs to be loaded. It's only loaded
//once per loadVF() call.
loadJS(false, true, "", sSifCfgUrl);
}
}
var bCVFLCalled = false; //XCMAX
/**
PUBLIC FUNCTION
Completes the validate_form.js
loading procedure, as begun by the call to loadVF()
Calling rules/sequence: It is required to call loadVF()
and configVF()
and this, in that order. completeVFLoad()
may only be called once, and must be done in the value of the body.onLoad
attribute (or at least, as the very last JavaScript line in your page).
SIGNATURE
completeVFLoad()
**/
function completeVFLoad() {
var f = completeVFLoad;
var sF_XCMAX = "completeVFLoad (XCMAX): ";
ciNotLoaded(sF_XCMAX, undefined);
if(bCVFLCalled) { //XCMAX
crsh("vf.cvfl1", f, sF_XCMAX + "This function was already called.");
bCVFLCalled = true; //XCMAX
} //XCMAX
if(aVfbc.length == 0) {//XCMAX
crsh("vf.cvfl2", f, sF_XCMAX + "Must call configVF().");
} //XCMAX
//Length is at least one
if(!df(aVfbc[0].sFrmNm) && aVfbc.length > 1) { //XCMAX
crsh("vf.cvf3", f, sF_XCMAX + "aVfbc.length is greater than one (" + aVfbc.length + "), but aVfbc[0].sFrmNm is.[undefined].");
} //XCMAX
for(var i = 0; i < aVfbc.length; i++) {
var sFnm = aVfbc[i].sFrmNm;
for(var j = (i + 1); j < aVfbc.length; j++) { //XCMAX
if(sFnm == aVfbc[j].sFrmNm) { //XCMAX
crsh("vf.cvfl4", f, sF_XCMAX + ": configVF was called twice for the form named '" + sFnm + "'. [i=" + i + ", j=" + j + "]");
} //XCMAX
} //XCMAX
if(aVfbc.length > 1 || df(aVfbc[0].sFnm)) { //XCMAX
//[undefined] is a legal form name when the length equals zero.
if(!df(sFnm)) { //XCMAX
crsh("vf.cvfl5", f, sF_XCMAX + "configVF was called multiple times, but call number " + (i + 1) + ", has a form name of [undefined]. [undefined] is a legal form name only when configVF is called a single time.");
} //XCMAX
//These tests will fail (actually or conceptually) when
//the name is undefined.
if(eval("!df(document." + sFnm + ")")) { //XCMAX
crsh("vf.cvfl6", f, sF_XCMAX + ": configVF was called for a form named '" + sFnm + "', but no form having that name exists.");
} //XCMAX
if(sFnm.substring(0, sFRM_NM_VFPD.length) == sFRM_NM_VFPD) {//XCMAX
crsh("vf.cvfl7", f, sF_XCMAX + "configVF was called for a form named '" + sFnm + "'. No form name may start '" + sFRM_NM_VFPD + "'.");
} //XCMAX
} //XCMAX
}
commitVFPDValues();
}
/**
PUBLIC FUNCTION
Configure the behavior of validate_form.js
for a single form, to define the default cibc and debugging behavior.
Calling rules/sequence: The call to this function is required, must be after the call to loadVF()
, and before the (optional) call to configVFPD()
. configVF
may only be called once per form.
PARAMETERS
Required parameters are detoned by '*'.
Name |
Description |
Values |
sb_cibcOnOff * |
Crash if bad vf-configuration? This value is the default used when Permanent VF-Diagnostics are off. |
Value |
VF-Config Analyzed? |
Advantage |
Disadvantage |
CIBC_ON |
Yes |
In development, this is critical for diagnostics and sanity-confirmation. |
Larger client-download, as both vf_cibVFCfg.js and vf_obj_dgnstcs.js must be loaded. When "cibc" is on, you may notice a hesitation when submitting forms having more-than-a-few elements. Both vf_cibVFCfg.js and vf_dbgVF.js depend on vf_obj_dgnstcs.js . |
CIBC_OFF |
No |
In production, when you are positive there are no errors in your vf-configuration, you can minimize client-download, and maximize speed of response. |
If there are any problems with your vf-configuration, vf_gtUsrErrCnt.gtUsrErrCnt() will behave unpredictably. |
|
i_dbgPerScreen * |
The default value for the vf_dbgVF.dbgVF() parameter i_dbgPerScreen This value is the default used when Permanent VF-Diagnostics are off. |
Must be a legal value as defined by vf_dbgVF.dbgVF() , although no error will be detected until this function is actually called. When this equals -1, debugging is not on, and vf_dbgVF.js and vf_obj_dgnstcs.js are not loaded, lowering your client download. Both vf_cibVFCfg.js and vf_dbgVF.js depend on vf_obj_dgnstcs.js . |
s_formName |
When provided, this is the name of the form to which this configuration refers. |
When provided, this must be the name of an actually-existing form (starting with something other than 'form_vfpd__ '). When this function is called multiple times, for multiple forms, it is required that this parameter be provided (defined), must be the name of an actually-existing form, and each call to configVF() must have a unique value for s_formName. In other words, this function, at a maximum, may only be called once per form. |
SIGNATURE
configVF(sb_cibcOnOff, i_dfltDbgPerScr, s_formName)
**/
function configVF(sb_cibcOnOff, i_dfltDbgPerScr, s_formName) {
if(!bLVFCalled) { //XCMAX
crsh("vf.cvf1", configVF, "configVF (XCMAX): Must call loadVF() first.");
} //XCMAX
//Add a new element to the end of aVfbc.
var vfbc = new VFBCfg(sb_cibcOnOff, i_dfltDbgPerScr, s_formName);
aVfbc[aVfbc.length] = vfbc;
bVFPDInUrl = (window.location.search.indexOf(sURLP_VFPD) != -1);
if(i_dfltDbgPerScr != -1) {
//Debugging is definitely needed when debugging is not -1.
loadDBG();
}
loadCIBC(vfbc.isCIBCOn());
}
function loadObjDgnstcs() {
loadJS(bLDD_OD, true, sJSDIR, "vf_obj_dgnstcs.js");
}
function loadCrashIf() {
loadJS(bLDD_CI, true, sJSDIR, "crash_if.js");
}
function loadCIBC(b_doLoad) {
//cibc is loaded only once per *page*, not per form.
if(b_doLoad || window.location.search.indexOf(sURLP_CIBC) != -1) {
loadJS(bLDD_CIBC, true, sJSDIR, "vf_cibVFCfg.js");
loadObjDgnstcs();
loadCrashIf();
}
}
/**
PUBLIC FUNCTION
Configure Permanent VF-Diagnostics, for when you choose to 'activate' it.
'Activating' pvf-diagnostics is done by calling wrtVFPDToolbar()
. This must be called before wrtVFPDToolbar()
. It is assumed, but not enforced, that wrtVFPDToolbar()
is called somewhere in the body of your page.
Calling rules/sequence: The call to configVFPD()
must come after the mandatory call to loadVF()
, and after the optional call to configVF()
. configVFPD()
may only be called once per form.
Unless sb_on
equals 'ON
', calling this function does not load anything into memory. The call to both this function, as well as to wrtVFPDToolbar()
, should remain in your web pages after production launch. This function is intended to be called right after loadVF()
, to keep all validate_form.js
configuration in one place, at the top of your HTML file.
Other notes...
Parameters
Required is denoted by '*'.
Name |
Description |
Values |
sb_on * |
Should pvf-diagnostics be on by default? |
ON : The pvf-diagnostics toolbar is displayed immediately on page load Passing in the url parameter 'vfpd ' turns pvf-diagnostics off.
OFF : pvf-diagnostics are not displayed until the parameter 'vfpd ' is passed into the url.
|
sb_cibcOnOff * |
When vfp-diagnostics is on (displayed), crash if bad vf-configuration? This value is the default used when Permanent VF-Diagnostics are on. See the configVF() parameter of the same name, for details, legal values, and for cibc behavior when vfp-diagnostics are off. |
|
sb_onLink * |
When vfp-diagnostics are off, should a trivial 'on' link be displayed in its place? This is a convenience tool to pass the parameter 'vfpd ' is passed into the url |
ON_LNK : A turn-on-vfpd link is displayed when vfp-diagnostics are off.
NO_ON_LNK : Nothing is displayed when vfp-diagnostics are off, which is necessary in production.
|
sb_offLink * |
When vfp-diagnostics are on, should the 'off' link be displayed? This link hides the vfp-diagnostics toolbar. |
OFF_LNK : The off link is displayed in the vfp-diagnostics are on.
NO_OFF_LNK : The off link is not displayed.
|
sb_resetLink * |
When vfp-diagnostics are on, should the 'reset' link be displayed? This link allows you to reset all vfp-diagnostic settings to their default values. |
RESET_LNK : A turn-on-vfpd link is displayed when vfp-diagnostics are off.
NO_RESET_LNK : Nothing is displayed when vfp-diagnostics are off, which is necessary in production.
|
sb_successDDB * |
When vfp-diagnostics are on, should the 'on-successful-submit-action' drop-down be displayed? This drop-down allows you to decide if, upon successful submission, the form should be actually submitted, or if only an alert box should be displayed. |
SUCCESS_DDB : The success ddb is displayed.
NO_SUCCESS_DDB : The success ddb is not displayed. Recommended in production, to prevent bogus submissions.
|
sb_cibcSection * |
When vfp-diagnostics are on, should the 'cibc' section be displayed? This section allows you to activate and deactivate vf_cibVFCfg.cibVFCfg() , to compare behavior. |
CIBC_SCTN : The cibc section is displayed.
NO_CIBC_SCTN : The cibc section is not displayed.
|
sb_cibcCrshDdb * |
When vfp-diagnostics are on and the CIBC-Section is displayed, should the 'cibc-crash' drop-down be displayed? This allows you to change how a crash behaves (alert box? redisplay?). |
CIBC_CRSH_DDB : The cibc-crash section is displayed.
NO_CIBC_CRSH_DDB : The cibc-crash section is not displayed, and previously-existing values for utility.bCRSH_ALRT , bCRSH_DGNSTCS and bCRSH_THROW are used.
|
ai_dbgPerScrDDB |
When defined, a drop-down box of these debugging-per-screen values is presented. The selected value is automatically--behind the scenes--communicated to vf_dbgVF.dbgVF() . |
Must be an array greater than zero elements in length, where all elements are defined and integers. Note that illegal values (such as -203) are okay, and will cause the expected 'vf.dvfjs1 ' developer error. Duplicate values are not illegal, but are not recommended. For example:
[6, 1, 2, 5, 7, 10, 20, 50]
Note that the value of loadVF() -s parameter i_dbgPerScrDefault is always the first value and is SELECTED . |
as_tstVFuncPosts |
The postfix of the demo function names. Each demo function should set values for the entire form, although this is not a requirement. Each of the values in this array are the display names for the buttons. |
Must be an array greater than zero elements in length, and every value must represent a function that actually exists ('vfpdtf__' + as_tstVFuncPosts[i] + '()' ) before wrtVFPDToolbar() is called. See the VFPD-dev tutorial for an example. |
s_formName |
When provided, this is the name of the form to which this configuration refers. |
When provided, this must be the name of an actually-existing form (starting with something other than 'form_vfpd__ '). When this function is called multiple times, for multiple forms, it is required that this parameter be provided (defined), must be the name of an actually-existing form, and each call to configVF() must have a unique value for s_formName (except for sDDB_DIVIDER , documented at the top of this page, which is ignored). In other words, this function, at a maximum, may only be called once per form. |
|
BACK Other notes regarding configVFPD()
- Recommended usage
- In development::
configVFPD("OFF", "CIBC_OFF", "ON_LINK", "OFF_LINK", "RESET_LINK", "SUCCESS_DDB", "NO_CIBC_SCTN", [appropriate_dbg_values], [appropriate_test_func_names]);
- In production::
configVFPD("OFF", "CIBC_OFF", "NO_ON_LINK", "OFF_LINK", "RESET_LINK", "NO_SUCCESS_DDB", "NO_CIBC_SCTN", [appropriate_dbg_values], [appropriate_test_func_names]);
- The prefix of the vfp-diagnostics form name (within the toolbar) is '
form_vfpd__
'. The name of the form it is diagnosing is thet postfix. No form of yours (that is passed to the FLStats constructor) may start with this.
window.location
:
- If the url (
window.location.search
) of the web page contains 'vfpd
', then the value of sb_on
is reversed (if originally 'ON
', now 'OFF
', and vice-versa).
- If the url (
window.location.search
) of the web page contains 'load_cibc
', then the value of sb_cibcOnOff
is reversed (if originally 'CIBC_ON
', now 'CIBC_OFF
', and vice-versa).
- The prefix for demo-value function names is '
vfpdtf__
'
SIGNATURE
configVFPD(sb_on, sb_cibcOnOff, sb_onLink, sb_offLink, sb_resetLink, sb_successDDB, sb_cibcSection, ai_dbgPerScrDDB, as_tstVFuncPosts, s_formName)
**/
function configVFPD(sb_on, sb_cibcOnOff, sb_onLink, sb_offLink, sb_resetLink, sb_successDDB, sb_cibcSection, sb_cibcCrshDdb, ai_dbgPerScrDDB, as_tstVFuncPosts, s_formName) {
var vfbc = gtVfbc(configVFPD, "configVFPD", s_formName);
vfbc.stVfpdc(sb_on, sb_cibcOnOff, sb_onLink, sb_offLink, sb_resetLink, sb_successDDB, sb_cibcSection, sb_cibcCrshDdb, ai_dbgPerScrDDB, as_tstVFuncPosts, s_formName);
loadVFPD(vfbc.isVfpdOn());
if(vfbc.isVfpdOn() && vfbc.bDCIBCOnOff) {
loadCIBC(true);
}
}
function gtSB(s_callingFunc, s_sbName, string_boolean, s_true, s_false) {
ciMissing(gtSB, s_callingFunc, s_sbName, string_boolean); //XCMAX
if(string_boolean == s_true) {
return true;
} else if(string_boolean == s_false) {
return false;
}
crsh("vf.gsb1", gtSB, s_callingFunc + " (XCMAX): The string_boolean parameter " + s_sbName + " must equal either s_true ([" + s_true + "]), or s_false ([" + s_false + "]).");
}
/**
PUBLIC FUNCTION
Analyzes the values in the form for validity and returns the user error message in a format appropriate for an alert()
.
PARAMETERS
f_orm
: A reference to the form to be analyzed. REQUIRED.
s_userErrPre
: The text snippet to precede every user-error message line. For example, ' -- '
. REQUIRED although it can be empty string. This is provided directly to [FLStats.]gtAFLSUsrErrs()
, as the s_linePre
parameter.
b_crshAlert
: In the case of an error (and only when crash_if.js
is downloaded), should the crsh be displayed in an alert box? When provided, and when VFP-Diagnostics is on, this parameter overrides the value selected in the 'CRSH' drop down.
b_crshDgnstcs
: In the case of an error (and only when crash_if.js is downloaded), should the crsh be displayed in a 'redirect' page? When provided, and when VFP-Diagnostics is on, this parameter overrides the value selected in the 'CRSH' drop down.
b_crshThrow
: In the case of an error (and only when crash_if.js
is downloaded), should the crsh be thrown to the JavaScirpt console? When provided, and when VFP-Diagnostics is on, this parameter overrides the value selected in the 'CRSH' drop down.
What this function does
- If your
f_orm
's vf-configuration has not yet been analyzed, analyze it (compile it into an array of FLStats). Analysis occurs when either of these conditions are met:
gtAFLSvf()
equals undefined
.
- The name of
f_orm
is different than the one previously analyzed. Specifically, (new FLStats(f_orm)).sNm != aFLStats[0].sNm)
- Analyze the form's vf-configuration, and crash if any errors are detected. This is done with
cibVFCfg()
. This is only done when your the FLStats array is created.
- Debug the form via
alert()
boxes, when i_dbgPerScreen
(as provided to loadVF()
) is defined and greater than zero.
- Analyze the validity of your form's values, as provided by your form's users, and return all the errors in a formatted string, appropriate for
alert()
-ing. This is done with gtUsrErrCnt()
and [FLStats.]gtAFLSUsrErrs()
.
SIGNATURE
getFormErrorMsgs(f_orm, s_userErrPre)
**/
function getFormErrorMsgs(f_orm, s_userErrPre, b_crshAlert, b_crshDgnstcs, b_crshThrow) {
var sF_XCMAX = "getFormErrorMsgs (XCMAX)";
var f = getFormErrorMsgs;
//If vfpd is active, and CRSH is selected, then
//that needs to be refreshed. It's successfully
//updated on page load, but not otherwise.
commitVFPDValues();
if(getFormErrorMsgs.arguments.length > 2) { //XCMAX
crsh("vf.gfem1", f, sF_XCMAX + ": " + getFormErrorMsgs.arguments.length + " parameters have been provided to this function, but only two are expected.");
} //XCMAX
ciMissing(getFormErrorMsgs, sF_XCMAX, "f_orm", f_orm);
ciMissing(getFormErrorMsgs, sF_XCMAX, "s_userErrPre", s_userErrPre);
if(!df(f_orm.name) || f_orm.name == "") {
crsh("vf.gfem1", f, sF_XCMAX + ": f_orm.name is undefined or zero characters in length.");
}
if(aVfbc.length == 0) {
crsh("vf.gfem2", f, sF_XCMAX + ": Must call configVF() first.");
}
var vfbc = gtVfbc(getFormErrorMsgs, "getFormErrorMsgs", f_orm.name);
//Set utility.crsh() behavior
bCRSH_ALRT = df(b_crshAlert)? b_crshAlert : vfbc.bCrshAlrt;
bCRSH_DGNSTCS = df(b_crshDgnstcs)? b_crshDgnstcs : vfbc.bCrshDgnstcs;
bCRSH_THROW = df(b_crshThrow)? b_crshThrow : vfbc.bCrshThrow;
ciNotLoaded(sF_XCMAX, vfbc);
//Get the array of FLStats for this form.
var aFLS4Frm = gtAFLSvf(vfbc.sFrmNm);
//Should configuration be analyzed, and then should we crash
//if there's a problem with it?
var bCIBC = false;
if(!df(aFLS4Frm)) {
//The form has not yet been analyzed.
//We need to re-analyze the form.
bCIBC = true;
//fl_stats.gtAFLS()
var aFLS = gtAFLS(f_orm);
//We've made it this far, so the form's vf configuration
//is good. If it's not good, we would have not made it
//past the previous line.
aFLS4Frm = aFLS;
//Now the form's statistics exist in the global aFLStats.
}
if(bLDD_DBG) {
//vf_cib_cfg.js has been imported, so this function has
//been defined. The only way this is defined is when
//i_dps has been set, at some point to something other
//than -1. Even if it is -1 now, it's so fast it's not
//worth *not* calling this.
dbgVF(aFLS4Frm, vfbc.iDDPS, false);
}
//We need to under normal circumstances &&
//The code is available &&
//They want to
if(bLDD_CIBC && bCIBC && vfbc.isCIBCOn()) {
cibVFCfg(aFLS4Frm);
}
//fl_stats.gtAFLSUsrErrs()
return (gtUsrErrCnt(aFLS4Frm) > 0)
? gtAFLSUsrErrs(aFLS4Frm, "", s_userErrPre, "")
: "";
}
function loadVFPD(b_on) {
loadJS(bLDD_VFPD, b_on, sJSDIR, "vf_perm_diagnostics.js");
}
function loadDBG() {
loadJS(bLDD_DBG, true, sJSDIR, "vf_dbgVF.js");
loadObjDgnstcs();
loadCrashIf();
}
function loadJS(b_alreadyLoaded, b_doLoad, s_dir, s_jsFile) {
if(b_alreadyLoaded || !b_doLoad) {
//It was already loaded, or we don't want to load it.
return;
}
//We want to load it, and it's not yet been loaded.
var sLoad = '';
if(bDbgJSLoads) {
alert("About to load...\n\n" + sLoad);
}
wrt(sLoad);
}
/**
PUBLIC FUNCTION
Activates Permanent VF-Diagnostics by displaying the vfpd-toolbar.
It is required that you call configVFPD()
before calling this function, and that this call be outside of the form that you are diagnosing.
Note that the demo functions (the postfixes of which are represented by the configVFPD()
parameter as_tstVFuncPosts
) must actually exist by the point this function is called.
PARAMETERS
s_nameLink
: The 'name' link. When provided, this is the value returned after the hash ('#') in the 'OFF
', 'RESET
' and 'Load CIBC
' links. When undefined, no name link is put in any url.
s_formName
: The name of the form to print the vfp-diagnostics toolbar for. If undefined, it is expected that configVF()
and configVFPD()
were called only once, and with no s_formName
parameter.
SIGNATURE
wrtVFPDToolbar(s_nameLink, s_formName)
**/
function wrtVFPDToolbar(s_nameLink, s_formName) {
if(aVfbc.length == 0) {
crsh("vf.wvfpdt1", wrtVFPDToolbar, "wrtVFPDToolbar (XCMAX): Must call configVF() first.");
}
if(df(s_nameLink) && (s_nameLink == "" ||
s_nameLink.indexOf("#") != -1)) {
crsh("vf.wvfpdt2", wrtVFPDToolbar, "wrtVFPDToolbar (XCMAX): s_nameLink (currently '" + s_nameLink + "') must be at least one character in length, and must not contain '#'.");
}
var vfbc = gtVfbc(wrtVFPDToolbar, "wrtVFPDToolbar", s_formName);
if(vfbc.isVfpdOn()) {
loadVFPD(true);
if(!bLDD_DBG && df(vfbc.aiDPSddb)) {
//Debugging has not yet been loaded, and the ddb of
//i_dbgPerScreen *will* be displayed.
loadDBG();
}
ciNotLoaded("wrtVFPDToolbar (XCMAX)", vfbc);
wrtVFPDRaw(vfbc, s_nameLink);
} else {
//When they turn off vfp-diagnostics, their selections
//need to be removed from memory.
vfbc.turnDOnOff(false);
if(vfbc.bOnLnk) {
wrt('[vfpd on]
');
}
}
}
/**
AUTOMATICALLY CALLED BY completeVFLoad()
Commit all the choices made in the vfp-diagnostics toolbar into memory.
Calling rules/sequence: When vfp-diagnostics is used (activated by wrtVFPDToolbar()
), it is recommended that you call this function in the value of the body.onLoad
attribute. When called, it must be made after the call to completeVFLoad()
.
The only purpose of (directly calling) this function is to prevent this known issue: When you select something in the vfp-diagnostics toolbar, that change is immediately committed. When you then reload the page, your selections remain, but are uncommitted from memory. Calling this function recommits your selections.
This automatically re-commits the selections for every form/vfpd-toolbar.
SIGNATURE
commitVFPDValues()
**/
function commitVFPDValues() {
if(bLDD_VFPD) {
updateVFPDCRaw();
}
}
/**
PUBLIC FUNCTION
Provide an alternative array of FLStats to validate_form.getFormErrorMsgs()
.
Get with gtAFLSvf()
Normally, when gtAFLSvf('FORM_NAME')
is undefined, validate_form.getFormErrorMsgs()
analyzes your form, and generates an array of FLStats from it. When gtAFLSvf('FORM_NAME')
is defined, then the array returned by it is used instead.
When initVF()
is called, it calls this function, for every existing form:
stAFLSvf(undefined, 'FORM_NAME');
Use this function carefully, as a_flStats
is assumed to be completely valid. Use fl_stats.gtAFLS
to assure that it is.
PARAMETERS
a_flStats
: The array of FLStats for validate_form.js
to use. When defined, getFormErrorMsgs()
uses it instead of analyzing the form. When undefined, getFormErrorMsgs()
analyzes your form and generates an array of FLStats
for itself.
s_formName
: The name of the form whose FLStats
array you wish to get. If only one form exists on the page, this is ignored. Otherwise, this is required, and must be the name of an existing form.
SIGNATURE
stAFLSvf(a_flStats, s_formName)
**/
function stAFLSvf(a_flStats, s_formName) {
var vfbc = gtVfbc(stAFLSvf, "stAFLSvf", s_formName);
vfbc.aFLStats = a_flStats;
}
/**
PUBLIC FUNCTION
Get the FLStats
array, for this form, currently used by getFormErrorMsgs()
and dbgVF()
, for analysis.
Set with stAFLSvf()
The postfix 'vf' is at the end of this function's name, to not confuse it with [fl_stats.]gtAFLS()
.
If this function returns undefined
, then getFormErrorMsgs()
analyzes the form, generates an array of FLStats
from it, and sets that array into stAFLSvf()
.
PARAMETERS
s_formName
: The name of the form whose FLStats
array you wish to get. If only one form exists on the page, this is ignored. Otherwise, this is required, and must be the name of an existing form. Use this function carefully, as it is not verified for validity.
RETURNS
a_siFmt
Exactly as provided to stAFLSvf()
.
SIGNATURE
gtAFLSvf(s_formName)
**/
function gtAFLSvf(s_formName) {
return gtVfbc(gtAFLSvf, "gtAFLSvf", s_formName).aFLStats;
}
/**
PUBLIC FUNCTION
Get the current url, perhaps with the vfp-diagnostics and cibc url parameters.
PARAMETERS
b_vfpdP
: Should the url parameter 'vfpd
' be in the returned url? If true, then this parameter is preserved if already in window.location.search
, and added if not. If false, then this parameter is deleted from window.location.search
, should it be there.
b_cibcP
: Should the url parameter 'load_cibc
' be in the returned url?
b_resetLink
: Is this the reset link? If true, then a random parameter is added to the url, to force a reload. Otherwise the link does nothing. If false, there is no parameter added.
RETURNS
Note that this returns a random extra parameter (starting with 'vfrndp_
' and ending in four random numbers) in order to force a reload. Also, the hash (#name
) is always returned.
For example... ([nothing] means false)
Original url |
b_vfpdP |
b_cibcP |
Returned url |
http://www.x.com/mypage.html |
|
|
http://www.x.com/mypage.html |
true |
|
http://www.x.com/mypage.html?vfpd |
|
true |
http://www.x.com/mypage.html?load_cibc |
true |
true |
http://www.x.com/mypage.html?vfpd&load_cibc |
http://www.x.com/mypage.html?vfpd |
|
|
http://www.x.com/mypage.html |
true |
|
http://www.x.com/mypage.html?vfpd |
|
true |
http://www.x.com/mypage.html?load_cibc |
true |
true |
http://www.x.com/mypage.html?vfpd&load_cibc |
http://www.x.com/mypage.html?load_cibc |
|
|
http://www.x.com/mypage.html |
true |
|
http://www.x.com/mypage.html?vfpd |
|
true |
http://www.x.com/mypage.html?load_cibc |
true |
true |
http://www.x.com/mypage.html?load_cibc&vfpd |
http://www.x.com/mypage.html?x=1&vfpd |
|
|
http://www.x.com/mypage.html?x=1 |
true |
|
http://www.x.com/mypage.html?x=1&vfpd |
|
true |
http://www.x.com/mypage.html?x=1&load_cibc |
true |
true |
http://www.x.com/mypage.html?x=1&vfpd&load_cibc |
http://www.x.com/mypage.html?load_cibc&x=1 |
|
|
http://www.x.com/mypage.html?x=1 |
true |
|
http://www.x.com/mypage.html?x=1&vfpd |
|
true |
http://www.x.com/mypage.html?load_cibc&x=1 |
true |
true |
http://www.x.com/mypage.html?load_cibc&x=1&vfpd |
SIGNATURE
gtDUrl(b_vfpdP, b_cibcP, b_resetLink)
**/
function gtDUrl(b_vfpdP, b_cibcP, b_resetLink) {
var url = window.location;
var sq = url.search;
sq = addDelUrlP(sq, b_vfpdP, sURLP_VFPD);
sq = addDelUrlP(sq, b_cibcP, sURLP_CIBC);
if(b_resetLink) {
//Forces a reload. When the link url is exactly the same as
//the current url, the link does nothing.
//What's the previous random link?
var sRND_PRE = "vfrndp_";
var iPOST_LEN = 4;
var iIdxPrevRnd = sq.indexOf(sRND_PRE);
if(iIdxPrevRnd != -1) {
sq = addDelUrlP(sq, false, sq.substring(iIdxPrevRnd, iIdxPrevRnd + sRND_PRE.length + iPOST_LEN));
}
//And now add a new random link.
var sRnd = ((new Date()).getTime() + "");
sRnd = sRnd.substring((sRnd.length - iPOST_LEN), sRnd.length);
sq = addDelUrlP(sq, true, sRND_PRE + sRnd);
}
//MUST SPLIT "//" IN THE URL, OR IT AND THE REST OF THE LINE
//WILL BE OBLITERATED AS A COMMENT.
return url.protocol + "/" + "/" + url.host + url.pathname + sq;
}
/**
PUBLIC FUNCTION
Should the form be submitted on success?
'Success' is defined as when all values in the form are deemed proper, according to your vf-configuration.
PARAMETERS
f_orm
: The form that may or may not need to be submitted. REQUIRED
RETURNS
true
: when the form should be submitted. The form should be submitted when either of the following conditions are met:
- VFP-Diagnostics are off
- VFP-Diagnostics are on, and '
SBMT
' is selected in the 'SUCCESS
' drop-down.
false
: if VFP-Diagnostics are on, and 'alert
' is selected in the 'SUCCESS
' drop-down.
SIGNATURE
doSubmitOnSuccess(f_orm)
>
**/
function doSubmitOnSuccess(f_orm) {
ciMissing(doSubmitOnSuccess, "doSubmitOnSuccess (XCMAX)", "f_orm", f_orm);
return gtVfbc(doSubmitOnSuccess, "doSubmitOnSuccess", f_orm.name).bSbmtOnSuccess;
}
function VFBCfg(sb_cibcOnOff, i_dfltDbgPerScr, s_formName) {
var sF = "VFBCfg";
var sF_XCMAX = sF + " (XCMAX)";
ciMissing(VFBCfg, sF_XCMAX, "sb_cibcOnOff", sb_cibcOnOff);
ciMissing(VFBCfg, sF_XCMAX, "i_dfltDbgPerScr", i_dfltDbgPerScr);
this.bCIBCOnOff = gtSB(sF, "sb_cibcOnOff", sb_cibcOnOff, "CIBC_ON", "CIBC_OFF");;
this.iDfltDPS = i_dfltDbgPerScr;
//May be undefined, meaning 'form_vfpd__undefined'!!!
//
this.sFrmNm = s_formName;
//VFPD
this.stVfpdc = pb_stVfpdc;
//Config
this.bDOnDflt;
this.bDCIBCOnOff = false;
this.bOnLnk = false;
this.bOffLnk = false;
this.bResetLnk = false;
this.bSuccessDDB = false;
this.bCIBCSctn = false;
this.bCIBCCrshDdb = false;
this.asTstngVFuncPost;
this.aiDPSddb;
//State
this.bDOn;
this.bCIBCDoCrsh;
this.bSbmtOnSuccess;
this.iDDPS;
this.bCrshAlrt;
this.bCrshDgnstcs;
this.bCrshThrow;
this.bOrigCrshAlrt = bCRSH_ALRT;
this.bOrigCrshDgnstcs = bCRSH_DGNSTCS;
this.bOrigCrshThrow = bCRSH_THROW;
this.turnDOnOff = pb_turnDOnOff;
this.isCIBCOn = pb_isCIBCOn;
this.isVfpdOn = pb_isVfpdOn;
this.turnDOnOff(false);
}
function pb_turnDOnOff(b_onOff) {
this.bCIBCDoCrsh = false;
//If on: Don't submit (by default)
//If off: Do submit.
this.bSbmtOnSuccess = !b_onOff;
this.iDDPS = this.iDfltDPS;
this.bDOn = b_onOff;
if(b_onOff && this.bCIBCCrshDdb) {
this.bCrshAlrt = true;
this.bCrshDgnstcs = false;
this.bCrshThrow = false;
} else {
this.bCrshAlrt = this.bOrigCrshAlrt;
this.bCrshDgnstcs = this.bOrigCrshDgnstcs;
this.bCrshThrow = this.bOrigCrshThrow;
}
}
function pb_isCIBCOn() {
var b = ((!this.bDOn && this.bCIBCOnOff) ||
(this.bDOn && this.bCIBCSctn && this.bCIBCDoCrsh));
if(!df(b)) {
crsh("vf.vfbc.icibco1", this.isCIBCOn, "isCIBCOn (XCMAX sanity check): b is undefined?! [this.bDOn=" + this.bDOn + ", this.bCIBCOnOff=" + this.bCIBCOnOff + ", this.bCIBCDoCrsh=" + this.bCIBCDoCrsh + "]");
}
return b;
}
/**
Should Permanent VF-Diagnostics be displayed?
**/
function pb_isVfpdOn() {
return (df(this.bDOnDflt) && this.bDOnDflt != bVFPDInUrl);
}
function pb_stVfpdc(sb_on, sb_cibcOnOff, sb_onLink, sb_offLink, sb_resetLink, sb_successDDB, sb_cibcSection, sb_cibcCrshDdb, ai_dbgPerScrDDB, as_tstVFuncPosts, s_formName) {
var sF = "configVFPD";
if(df(this.bDOnDflt)) { //XCMAX
crsh("vfbc.svfpdc1", this.stVfpdc, sF + " (XCMAX): Already called " + sF + "() for s_formName ('" + s_formName + "').");
} //XCMAX
this.aFLStats;
this.bDOnDflt = gtSB(sF, "sb_on", sb_on, "ON", "OFF");
this.bDCIBCOnOff = gtSB(sF, "sb_cibcOnOff", sb_cibcOnOff, "CIBC_ON", "CIBC_OFF");
this.bOnLnk = gtSB(sF, "sb_onLink", sb_onLink, "ON_LNK", "NO_ON_LNK");
this.bOffLnk = gtSB(sF, "sb_offLink", sb_offLink, "OFF_LNK", "NO_OFF_LNK");
this.bResetLnk = gtSB(sF, "sb_resetLink", sb_resetLink, "RESET_LNK", "NO_RESET_LNK");
this.bSuccessDDB = gtSB(sF, "sb_successDDB", sb_successDDB, "SUCCESS_DDB", "NO_SUCCESS_DDB");
this.bCIBCSctn = gtSB(sF, "sb_cibcSection", sb_cibcSection, "CIBC_SCTN", "NO_CIBC_SCTN");
this.bCIBCCrshDdb = gtSB(sF, "sb_cibcCrshDdb", sb_cibcCrshDdb, "CIBC_CRSH_DDB", "NO_CIBC_CRSH_DDB");
if(df(as_tstVFuncPosts)) { //XCMAX
cibRA(sF + " (XCMAX)", "as_tstVFuncPosts", as_tstVFuncPosts);
for(var i = 0; i < as_tstVFuncPosts.length; i++) { //XCMAX
for(var j = (i + 1); j < as_tstVFuncPosts.length; j++) { //XCMAX
if(as_tstVFuncPosts[i] == as_tstVFuncPosts[j] && //XCMAX
as_tstVFuncPosts[i] != sDDB_DIVIDER && //XCMAX
as_tstVFuncPosts[j] != sDDB_DIVIDER) { //XCMAX
crsh("vfbc.svfpdc2", this.stVfpdc, sF + " (XCMAX): as_tstVFuncPosts[" + i + "] and as_tstVFuncPosts[" + j + "] are the same: '" + as_tstVFuncPosts[i] + "'. Form name='" + this.sFrmNm + "'");
} //XCMAX
} //XCMAX
} //XCMAX
} //XCMAX
if(df(ai_dbgPerScrDDB)) { //XCMAX
cibRA(sF, "ai_dbgPerScrDDB", ai_dbgPerScrDDB); //XCMAX
for(var i = 0; i < ai_dbgPerScrDDB.length; i++) { //XCMAX
if(!df(ai_dbgPerScrDDB) || !isNum(ai_dbgPerScrDDB[i], "false")) { //XCMAX
crsh("vfbc.svfpdc2", this.stVfpdc, sF_XCMAX + ": ai_dbgPerScrDDB[" + i + "] (" + ai_dbgPerScrDDB[i] + ") must be defined, and an integer.");
} //XCMAX
} //XCMAX
} //XCMAX
this.asTstngVFuncPost = as_tstVFuncPosts;
this.aiDPSddb = ai_dbgPerScrDDB;
//May be undefined, meaning 'form_vfpd__undefined'!!!
//
//Must have this same variable in VFBCfg
this.sFrmNm = s_formName;
this.turnDOnOff(this.bDOnDflt);
}
function gtVfbc(f_calling, s_callingFunc, s_formName) {
if(!df(aVfbc[0].sFrmNm)) {
//A form "named" undefined may only be when there's a
//single call to configVF per page. This is verified in
//completeVFLoad()
return aVfbc[0];
}
//There's at least one other element.
var sFrmNmLst = " Form names: ['";
for(var i = 0; i < aVfbc.length; i++) {
if(i > 0) {
sFrmNmLst += "', '";
}
sFrmNmLst += aVfbc[i].sFrmNm;
if(s_formName == aVfbc[i].sFrmNm) {
return aVfbc[i];
}
}
sFrmNmLst += "']";
crsh("vf.gc1", f_calling, s_callingFunc + " (XCMAX): No VFBCfg exists for a form named s_formName ('" + s_formName + "'). Must call loadVF(), configVF() and/or configVFPD() before calling this function. [aVfbc.length=" + aVfbc.length + "]" + sFrmNmLst);
}
function pb_setAFLS(a_flStats) {
}
/**********************************************************
**********************************************************
**********************************************************
E:\a_sandbox\validate_form_js\utility.js...START
**********************************************************
**********************************************************
**********************************************************/
/**
[BSD License. This license contains no advertising clause.]
validate_form.js: A comprehensive solution for validating the most common rules in HTML forms.
http://sourceforge.net/projects/validateformjs
Copyright (C) 2003-2005, Jeff Epstein
All rights reserved.
Modifications: No
Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met:
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* If modifications are made to source code then this license should indicate that fact in the "Modifications" section above.
* Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[NOTE: This license contains NO advertising clause.]
**/
/**
JS FILE OVERVIEW DOCUMENTATION
Random, standalone functions.
**/
/**
PUBLIC FUNCTION
An alias for document.writeln()
.
See wrtnl()
.
This function also returns the string so you can accumulate the output, and "alert" it all at once.
SIGNATURE
wrt(s_tring)
**/
function wrt(s_tring) {
document.writeln(s_tring);
return s_tring + '\n';
}
/**
PUBLIC FUNCTION
An alias for document.write()
.
See wrt()
.
This function also returns the string so you can accumulate the output, and "alert" it all at once.
SIGNATURE
wrtnl(s_tring)
**/
function wrtnl(s_tring) {
document.write(s_tring);
return s_tring;
}
/**
PUBLIC FUNCTION
Is the provided variable defined?
RETURNS
SIGNATURE
df(v_ariable)
**/
function df(v_ariable) {
return (v_ariable != undefined);
}
/**
PUBLIC FUNCTION
Add or delete a particular url parameter to the provided url-query (?x&y=2&z
) string.
PARAMETERS
s_urlq
: The window.location.search
. Assumed to be valid and provided. Must be either empty string (''), or start with a question mark ('?').
b_pNeeded
: Is the url parameter desired? If true, yes. If false, no.
s_urlp
: The url parameter that should ultimately exist or not exist, depending on the value of b_pNeeded
, in the returned value.
RETURNS
- The url query string (either empty string [''], or a string starting with '?'), with
s_urlp
in or not in it, as appropriate. For example, if s_urlp
needed but not currently existing, then s_urlp is added to s_urlq
. If it's needed and already there, s_urlq
is returned as is...
SIGNATURE
addDelUrlP(s_urlq, b_pNeeded, s_urlp)
**/
function addDelUrlP(s_urlq, b_pNeeded, s_urlp) {
if(b_pNeeded == (s_urlq.indexOf(s_urlp) != -1)) {
//Needed and already there...OR...
//Not needed and already not there.
//Done!
return s_urlq;
}
//They're opposite values.
if(b_pNeeded) {
//Needed, but not in url.
if(s_urlq.length > 0) {
//Preserve existing url params
return s_urlq + "&" + s_urlp;
} else {
return "?" + s_urlp;
}
} else {
//Not needed, but in url.
var iIdx = s_urlq.indexOf(s_urlp);
var iLen = s_urlp.length;
//-1 is okay, because if length > 0, then it's at least ?vfpd
if(s_urlq.substring((iIdx - 1), iIdx) == "&") {
iIdx--;
iLen++;
}
var s = s_urlq.substring(0, iIdx) + s_urlq.substring((iIdx + iLen), s_urlq.length);
if(s.substring(0, 2) == "?&") {
s = "?" + s.substring(2, s.length);
}
return (s == "?")
? ""
: s;
}
}
/**********************************************************
**********************************************************
**********************************************************
E:\a_sandbox\validate_form_js\utility.js...END
**********************************************************
**********************************************************
**********************************************************/
/**********************************************************
**********************************************************
**********************************************************
E:\a_sandbox\validate_form_js\si_fmt.js...START
**********************************************************
**********************************************************
**********************************************************/
/**
[BSD License. This license contains no advertising clause.]
validate_form.js: A comprehensive solution for validating the most common rules in HTML forms.
http://sourceforge.net/projects/validateformjs
Copyright (C) 2003-2005, Jeff Epstein
All rights reserved.
Modifications: No
Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met:
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* If modifications are made to source code then this license should indicate that fact in the "Modifications" section above.
* Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[NOTE: This license contains NO advertising clause.]
**/
/**
JS FILE OVERVIEW DOCUMENTATION
Define and manage a "string-integer" format, to be used by validate_form.js
to enforce values are legal values for items such as phone numbers, zip codes and social security numbers.
"String-integer" means an integer that is held inside a string variable. The reason to keep it a string is to preserve leading zeros. The actually-and-currently configured sif-attributes are listed at SIFmt
-Attributes sMsgTxt*
. For implementation details, see Tutorial: SIFmt sMsgTxt*
attributes.
Configuring your own SIFmt attributes
When you originally downloaded validate_form.js
, this is the code that ../../si_fmt_CONFIGURATION.js
contained:
//As defined in and required by validate_form.js. This
//notifies all other code that this JavaScript file has
//indeed been loaded.
bLDD_SIF_CFG = true;
//Zip5 A five-digit U.S. zip code.
//Zip5p4 A five-digit U.S. zip code with an optional four-digit postfix.
//Phone7 A seven-digit U.S. phone number.
//Phone10 A ten digit U.S. phone number
//Ssn A nine-digit U.S. Social Security Number
var aSIFmt = [
new SIFmt("Zip5", "00001", "99999"),
new SIFmt("Zip5p4", "00001", "99999", "0001", "9999"),
new SIFmt("Phone7", "1001000", "9999999"),
new SIFmt("Phone10", "1001001000", "9999999999"),
new SIFmt("Ssn", "000000001", "999999999")
];
//vf_stASIF.stASIF()
stASIF(aSIFmt);
|
Change the contents of this file to be whatever you like (consider backing up this file consistently and frequently), or comment out the call to stASIF
, to have no sif-attributes at all.
**/
var sCNSTR_XCMAX = "SIFmt.constructor (XCMAX)";
/**
PUBLIC FUNCTION
Constructor: Create a new SIFmt
.
PARAMETERS
sMTPost
: The string to use as the postfix for the validate_form.js
'sMsgTxt*
' attribute. For example, if this is 'Ssn
', then the attribute for it is named 'sMsgTxtSsn
'. REQUIRED, may not be less than one character in length, or equal 'Dec', 'Email', or 'Int', and may contain only letters, digits and underscores.
si_rqdMin
: The minimum allowable value for the required part of the format. REQUIRED and must be at least one digit, and the same length as, but not greater than si_rqdMax
.
si_rqdMax
: The maximum allowable value for the required part of the format. REQUIRED and must be at least one digit, and the same length as, but not less than si_rqdMin
.
si_altMin
: The minimum allowable value for the alternate part of the format. When provided, it must be at least one digit, and the same length as, but not greater than si_altMax
(which must also be provided).
si_altMax
: The maximum allowable value for the alternate part of the format. When provided, it must be at least one digit, and the same length as, but not less than si_altMin
(which must also be provided).
SIGNATURE
SIFmt(s_msgTxtPostfix, si_rqdMin, si_rqdMax, si_altMin, si_altMax)
**/
function SIFmt(s_msgTxtPostfix, si_rqdMin, si_rqdMax, si_altMin, si_altMax) {
ciMissing(SIFmt, sCNSTR_XCMAX, "s_msgTxtPostfix", s_msgTxtPostfix);
ciMissing(SIFmt, sCNSTR_XCMAX, "si_rqdMin", si_rqdMin);
ciMissing(SIFmt, sCNSTR_XCMAX, "si_rqdMax", si_rqdMax);
if(s_msgTxtPostfix == 'Dec' || //XCMAX
s_msgTxtPostfix == 'Email' || //XCMAX
s_msgTxtPostfix == 'Int') { //XCMAX
crsh("snf.cnstr1", SIFmt, sCNSTR_XCMAX + ": s_msgTxtPostfix (currently '" + s_msgTxtPostfix + "') must not equal 'Dec', 'Email', or 'Int'.");
} //XCMAX
//Ascending order: Numbers, then _, then letters
var acLtrsDgtsUndrscr = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0']; //XCMAX
for(var i = 0; i < (s_msgTxtPostfix.length - 1); i++) { //XCMAX
var c = s_msgTxtPostfix.substring(i, (i + 1)).toLowerCase(); //XCMAX
if(isInAscRA(c, acLtrsDgtsUndrscr)) { //XCMAX
continue; //XCMAX
} else { //XCMAX
crsh("snf.cnstr2", SIFmt, sCNSTR_XCMAX + ": s_msgTxtPostfix (currently '" + s_msgTxtPostfix + "') may not contain anything but letters, digits, and underscores. Character at index " + i + " ('" + c + "') is illegal.");
} //XCMAX
} //XCMAX
if(df(si_altMin) ^ df(si_altMax)) { //XCMAX
//Exactly one is defined, but not both.
crsh("snf.cnstr2", SIFmt, sCNSTR_XCMAX + ": si_altMin ('" + si_altMin + "') and si_altMax ('" + si_altMax + "') must both be either undefined or defined.");
} //XCMAX
//The alternate bounds are either both provided, or not.
cibLnRng(si_rqdMin, si_rqdMax, "si_rqdMin", "si_rqdMax", ""); //XCMAX
cibLnRng(si_altMin, si_altMax, "si_altMin", "si_altMax", "When provided, ");//XCMAX
//Internal variables
this.sMTPost = s_msgTxtPostfix;
this.siRqMn = si_rqdMin;
this.siRqMx = si_rqdMax;
this.siLtMn = si_altMin;
this.siLtMx = si_altMax;
this.gtFmtV = pb_gtFmtV;
this.isFmtEq = pb_isFmtEq;
this.type = "SIFmt";
}
/**
PUBLIC FUNCTION
Is the provided SIFmt
's format equal to this SIFmt
's format?
PARAMETERS
si_fmt
: The SIFmt
whose format should be compared to the format of this SIFmt
. REQUIRED
RETURNS
(si_fmt.siRqMn == this.siRqMn &&
si_fmt.siRqMx == this.siRqMx &&
si_fmt.siLtMn == this.siLtMn &&
si_fmt.siLtMx == this.siLtMx)
SIGNATURE
pb_isFmtEq(si_fmt)
**/
function pb_isFmtEq(si_fmt) {
ciMissing(this.isFmtEq, "isFmtEq (XCMAX)", "si_fmt", si_fmt);
return (si_fmt.siRqMn == this.siRqMn &&
si_fmt.siRqMx == this.siRqMx &&
si_fmt.siLtMn == this.siLtMn &&
si_fmt.siLtMx == this.siLtMx);
}
/**
PUBLIC FUNCTION
Get the provided string after eliminating all non-digits.
PARAMETERS
s_tring
: The value to string numbers from. REQUIRED
RETURNS
- A string with all non-digits eliminated.: For example, when
s_tring
equals
'(215) 555-1212
',
'2155551212
'
is returned.
''
: when s_tring
contains no digits. Note that decimal points ('.') and negative signs (dashes, '-') are eliminated.
SIGNATURE
gtDgts(s_tring)
**/
function gtDgts(s_tring) {
ciMissing(gtDgts, "gtDgts (XCMAX)", "s_tring", s_tring);
if(/^\D$/.test(s_tring)) {
//There are no numbers at all.
return "";
}
//There is at least one number.
var asNumberParts = s_tring.split(/\D/);
var sNumber = asNumberParts[0];
for(var i = 1; i < asNumberParts.length; i++) {
sNumber += asNumberParts[i];
}
return sNumber;
}
/**
PUBLIC FUNCTION
When valid for this format, get the digits from value string.
PARAMETERS
s_value
: The value to analyze for format-conformity. REQUIRED
RETURNS
- A string containing only digits: when
s_value
is legal according to this format, then it is returned with all non-digits eliminated. For example, (215) 555-1212
, if valid, is returned as 2155551212
.
undefined
: when the value is not legal for this format.
SIGNATURE
pb_gtFmtV(s_value)
**/
function pb_gtFmtV(s_value) {
ciMissing(this.gtFmtV, "gtSIFromFormat (XCMAX)", "s_value", s_value);
//util_string.gtDgts()
var sDigits = gtDgts(s_value);
var siRqdPart;
var siAltPart;
var iStrippedLen = sDigits.length;
//We're only comparing against the "minimum" bound, because
//we know that the minimum and maximum formats are the same
//length.
if(iStrippedLen < this.siRqMn.length) {
//The value is shorter than it is required to be.
return undefined;
} //ELSE: The value is at least as long as required..
if(iStrippedLen > this.siRqMn.length) {
//The length of the value is greater than required, but
//that's okay if there's an alternate format.
if(!df(this.siLtMn)) {
//No alternate format. The length is illegal.
return undefined;
} //ELSE: There is an alternate format...
if(iStrippedLen !=
(this.siRqMn.length + this.siLtMn.length)) {
//...but the length of the value is not equal to either
//the required or required-plus-alternate formats length.
return undefined;
} //ELSE: ...and it is equal to the required-plus-
// alternate length.
siRqdPart = sDigits.substring(0, this.siRqMn.length);
siAltPart = sDigits.substring(this.siRqMn.length, iStrippedLen);
} else { //The value's length is exactly the required
//length.
siRqdPart = sDigits;
siAltPart = undefined;
}
if(!isInFrmtRng(siRqdPart, this.siRqMn, this.siRqMx)) {
//The required part of the value is out of range.
return undefined;
}
if(df(siAltPart) &&
!isInFrmtRng(siAltPart, this.siLtMn, this.siLtMx)) {
//The alternate part has been provided, and that part of
//the value is out of range.
return undefined;
}
//The format is totaly valid for this SIFmt.
return sDigits;
}
function isInFrmtRng(si_valuePart, si_frmtPartMin, si_frmtPartMax) {
var iValuePart = parseInt(si_valuePart, 10);
var iFPartMin = parseInt(si_frmtPartMin, 10);
var iFPartMax = parseInt(si_frmtPartMax, 10);
return (iValuePart >= iFPartMin &&
iValuePart <= iFPartMax);
}
/**********************************************************
**********************************************************
**********************************************************
E:\a_sandbox\validate_form_js\si_fmt.js...END
**********************************************************
**********************************************************
**********************************************************/
/**********************************************************
**********************************************************
**********************************************************
E:\a_sandbox\validate_form_js\fl_stats.js...START
**********************************************************
**********************************************************
**********************************************************/
/**
[BSD License. This license contains no advertising clause.]
validate_form.js: A comprehensive solution for validating the most common rules in HTML forms.
http://sourceforge.net/projects/validateformjs
Copyright (C) 2003-2005, Jeff Epstein
All rights reserved.
Modifications: No
Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met:
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* If modifications are made to source code then this license should indicate that fact in the "Modifications" section above.
* Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[NOTE: This license contains NO advertising clause.]
**/
/**
JS FILE OVERVIEW DOCUMENTATION
A wrapper for form objects (the form itself and elements therein).
Using FLStats
This class is automatically used by validate_form.js
, so you don't need to directly use this object at all.
To create an array of FLStats for your form, try the following:
function nlzForm(f_orm) {
var aFLStats = gtAFLS(f_orm);
dbgAFLS(aFLStats);
}
...
Local and public FLStats
variables
Except for sUsrErr
, all these variables are to be treated as read-only. Changing their values will result in unpredictable behavior. Attributes or functions not listed in this documentation should not be accessed.
this.sNm
: The name of the form object. If this.sType
equals 'form'
, then this is the 'name'
of the form (if provided) or "f_orm" (if no name is provided). Will never be undefined or empty string.
this.sType
: The type of the form object. Will equal one of the following: 'form
', 'text
', 'password
', 'textarea
', 'radio
', 'select-one
', 'checkbox
', 'select-multiple
'
this.obj
: A reference to the form object itself.
this.sAftrFrmNm
: Will equal either '.' or '['
'. See gtEvlCdLmntAttrNm() and gtEvlCdObjNm() for how its used.
this.sAftrAttrNm
: Will equal either '' (empty string) or '']
'. See gtEvlCdLmntAttrNm() and gtEvlCdObjNm() for how its used.
this.iTotOpts
: The total number of options in this multi-valued element. Will equal undefined when this element is single-valued.
this.flsFrm
: A pointer to the FLStats object representing the form in which this form element exists.
this.sUsrErr
: After calling validate_form.getFormErrorMsgs()
, this is set to the user error message, if any should the value of this form element be unacceptable. If the value is acceptable, or getFormErrorMsgs()
has not been called, this is undefined. This is the one variable which you can alter freely. It is not used anywhere else in the code.
When this.sType
equals 'form'
, the following attributes will all be undefined: this.sAftrFrmNm
, this.sAftrAttrNm
, this.iTotOpts
, this.sUsrErr
and this.flsFrm
Notes
- f_* functions are internal to FLStats.
pb_*
functions are intended for public use. pv_*
are not intended for public use.
- All boolean string values that are equal to "false" are *undefined* at the end of the constructor.
**/
/**
PUBLIC FUNCTION
Constructor: Create a new FLStats
with the provided form/form-element, form-FLStats
, and previous-array-of-FLStats
.
PARAMETERS
frm_frmLmnt
: The form or form element object to 'wrap'. REQUIRED and frm_frmLmnt.name
must be both defined and at least one character in length.. If fls_frm
is undefined, then this must be the form itself. When fls_frm
is defined, this must be a form_element within that form. All form objects provided to this constructor may not have a name equal to any other form on the same page. Forms not provided to this constructor are not required to have a name--however, those having a name must have one not equal to any other provided to this constructor.
a_prevFLS
: The array of FLStats
already analyzed in this form. Must be an array of FLStats where there is at least one element, and none are undefined. When fls_frm is undefined, this must also be undefined.
This array may only include FLStats
for form elements (no element may be the form itself). The purpose of providing this array is to ensure that checkbox sets and radio sets are analyzed as a whole, and not for each checkbox/radio element therein. This is required for validate_form.js
to work properly.
DISCARED OR USE?
After using this cnstr, useThisFLS()
must be called to determines if this FLStats
is worthy of keeping, or should be discarded.
validate_form.js
only handles certain types of form elements. For example, it does not handle hidden
, button
, submit
or reset
elements.
Also, each checkbox/radio set (set of checkbox or radio elements) has a single FLStats
, representing it as a whole. The second and subsequent checkbox/radio must be discarded for validate_form.js
to work properly.
NOTE
- Any boolean string
validate_form.js
attributes (such as 'bsTrimSpaces
') values set to 'false'
are automatically reset (by this cnstr) to undefined
. A 'false' boolean string attribue might as well not be defined at all. This simplifies the validate_form.js
source code.
SIGNATURE
FLStats(frm_frmLmnt, fls_frm, a_prevFLS)
**/
function FLStats(frm_frmLmnt, fls_frm, a_prevFLS) {
var ffl = frm_frmLmnt;
var f = FLStats;
var sFLSC_XCMAX = "FLStats.constructor (XCMAX): ";
//Parameter checking...START
//Note that "sXCMAX" is part of these variables' names.
ciMissing(FLStats, sFLSC_XCMAX, "frm_frmLmnt", ffl);
//Get the type of frm_frmLmnt...START
//(This section is not a sanity check, but must be right here.)
var iFflTypeIdx = gtVRAIdx("fls.c0", ffl.type, asOBJ_TYPES);
if(iFflTypeIdx == -1 &&
df(ffl.elements) &&
df(ffl.elements.length) &&
df(ffl.reset)) {
//Forms have no "type" attribute, but they all have an
//elements array, and a reset function. Hey, it's the
//least I could do. :' )
//asOBJ_TYPES[0]="form"
iFflTypeIdx = 0;
}
//iFflTypeIdx now equals...
//...-1 when it is a form element, but one we don't
// care about.
//...0 when it's the form (fls_frm must be undefined)
//...[Some other asOBJ_TYPES array index] when it is a
// form element and we do care about it.
//Get the type of frm_frmLmnt...END
if(df(fls_frm)) { //XCMAX
if(iFflTypeIdx == 0) { //XCMAX
crsh("fls.c1", f, sFLSC_XCMAX + "fls_frm is provided, but frm_frmLmnt is also a 'form' object.");
} //XCMAX
ciNotFLStats(sFLSC_XCMAX, "fls_frm", fls_frm);
if(fls_frm.sType != "form") {//XCMAX
crsh("fls.c2", f, sFLSC_XCMAX + "fls_frm, when provided, must have an 'sType' equal to 'form'. Currently, fls_frm.sType='" + fls_frm.sType + "'.");
} //XCMAX
//ELSE: fls_frm is undefined
} else { //XCMAX
if(df(a_prevFLS)) { //XCMAX
crsh("fls.c3", f, sFLSC_XCMAX + "When fls_frm is not provided, a_prevFLS must also be undefined. Currently, a_prevFLS=['" + a_prevFLS.join("', '") + "'].");
} //XCMAX
if(iFflTypeIdx != 0) { //XCMAX
crsh("fls.c4", f, sFLSC_XCMAX + "When fls_frm is not provided, frm_frmLmnt must be a form object. Currently, frm_frmLmnt.type=" + ffl.type + ", frm_frmLmnt.toString()=[" + ffl.toString() + "].");
} //XCMAX
} //XCMAX
if(df(a_prevFLS)) { //XCMAX
cibRA(sFLSC_XCMAX, "a_prevFLS", a_prevFLS);
} //XCMAX
//Parameter checking...END
//Everything seems good now...
//Variables and functions...START
//Basic info
this.sNm;
this.sType;
this.obj;
this.sAftrFrmNm;
this.sAftrAttrNm;
this.iTotOpts;
this.flsFrm; //A pointer to the form's FLStats
this.sUsrErr;
this.bUseThisFLS = false;
this.type = "FLStats";
this.useThisFLS = pb_useThisFLS;
this.gtCd4Attr = pb_gtCd4Attr;
this.gtCdAttrNm = pb_gtCdAttrNm;
this.gtCdFLSNm = pb_gtCdFLSNm;
this.gtAttrVRaw = pb_gtAttrVRaw;
this.gtEvlCdLmntAttrNm = pb_gtEvlCdLmntAttrNm;
this.gtEvlCdObjNm = pb_gtEvlCdObjNm;
this.gtEvalCode = pv_gtEvalCode;
this.isAttrAssc2Lmnt = pb_isAttrAssc2Lmnt;
this.gtAttrV = pb_gtAttrV;
this.isLmntVal1OrMore = pb_isLmntVal1OrMore;
this.gtLmntValSnglr = pb_gtLmntValSnglr;
this.gtLmntOptsTotal = pb_gtLmntOptsTotal;
this.gtLmntOptsChosen = pb_gtLmntOptsChosen;
this.ciFrm1OrMore = pv_ciFrm1OrMore; //XCMAX
this.gtFLS4Frm = pv_gtFLS4Frm;
this.gtLmntStats = pv_gtLmntStats;
this.unassociateFalseBS = pv_unassociateFalseBS;
//Variables and functions...END
if(df(fls_frm)) {
//This is a form element, not the form itself. All form
//elements have a pointer to the FLStats for the form.
this.flsFrm = fls_frm;
}
//validate_form.gtStrIdx() and .asOBJ_TYPES
if(iFflTypeIdx == -1) {
//This is a form element (as best we can determine above),
//but it's a type we don't care about. Perhaps it's a
//submit or reset or button or hidden...
this.bUseThisFLS = false;
//ELSE: We care about this type of element.
} else if(!df(fls_frm)) {
//This is the form itself.
this.gtFLS4Frm(ffl);
this.bUseThisFLS = true;
} else {
//This is an element in the form
this.bUseThisFLS = this.gtLmntStats(ffl, a_prevFLS);
}
if(!this.bUseThisFLS) {
//If you don't return now, the below sanity checks and
//unassociateFalseBS() calls will crash.
return;
}
//Must be after this.bUseThisFLS is known to be true.
if(!df(ffl.name) || //XCMAX
ffl.name == "") { //XCMAX
crsh("fls.c5", f, sFLSC_XCMAX + "frm_frmLmnt.name ([" + ffl.name + "]) must be defined, at least one character in length, and unique among all forms in this web page.");
} //XCMAX
this.sNm = ffl.name;
if(gtVRAIdx("fls.c6", this.sType, asOBJ_TYPES) == -1) {//XCMAX
crsh("fls.c7", f, sFLSC_XCMAX + "this.sType ('" + this.sType + "') is not one of these valid types: '" + asOBJ_TYPES.join("', '") + "'.");
}//XCMAX
if(df(this.iTotOpts) && //XCMAX
this.iTotOpts < 2) { //XCMAX
crsh("fls.c1", f, sFLSC_XCMAX + " (this.sNm='" + this.sNm + "'): This element is a multiple-value element, but there are less than two options?! One checkbox checkbox sets should be considered singular.\n\n" + sXCMAX);
} //XCMAX
//Regarding all boolean string attributes that happen to
//both undefined and equal to "false": Undefine them
//entirely. A boolean sting attribute equal to "false" is
//one that might as well not be associated at all. This
//makes the actual value consistent with the
//documentation, that boolean strings are only recognized
//when equal to "true" (assuming a legal boolean string
//value).
//validate_form.asVF_ATTRS
//asVF_ATTRS[7]="bsNoBadSubStrs"
this.unassociateFalseBS(7);
//asVF_ATTRS[10]="bsGlobalTrimSpaces"
this.unassociateFalseBS(10);
//asVF_ATTRS[11]="bsTrimSpaces"
this.unassociateFalseBS(11);
//asVF_ATTRS[12]="bsDontTrimSpaces"
this.unassociateFalseBS(12);
}
/**
PUBLIC FUNCTION
Accumulate all user form error messages into a single, alert()-ready string.
PARAMETERS
- All
s_*
parameters are REQUIRED, but may be empty string.
a_flStats
: The array of FLStats
potentially containing user error messages (in sUsrErr
). REQUIRED, must be a valid FLStats
array, and at least one element must have a defined value for sUsrErr
.
s_header
: The text to put at the top of the alert box.
s_linePre
: The text to put before each error line.
s_footer
: The text to put at the bottom of the alert box.
SIGNATURE
gtAFLSUsrErrs(a_flStats, s_header, s_linePre, s_footer)
**/
function gtAFLSUsrErrs(a_flStats, s_header, s_linePre, s_footer) {
var sF_XCMAX = "gtAFLSUsrErrs (XCMAX)";
cibAFLS(sF_XCMAX, "a_flStats", a_flStats);
ciMissing(gtAFLSUsrErrs, sF_XCMAX, "s_header", s_header);
ciMissing(gtAFLSUsrErrs, sF_XCMAX, "s_linePre", s_linePre);
ciMissing(gtAFLSUsrErrs, sF_XCMAX, "s_footer", s_footer);
var sErrors = "";
for(var i = 0; i < a_flStats.length; i++) {
if(df(a_flStats[i].sUsrErr)) {
sErrors += s_linePre + a_flStats[i].sUsrErr;
if(i < (a_flStats.length - 1)) {
sErrors += "\n";
}
}
}
if(sErrors == "") { //XCMAX
crsh("os.guefaos1", gtAFLSUsrErrs, sF_XCMAX + "No element in a_flStats has a defined value for sUsrErr.");
} //XCMAX
return s_header + sErrors + s_footer;
}
/**
PUBLIC FUNCTION
Get an array of FLStats
representing the provided form. Call this at form submission to analyze the form and create the aFLStats array based upon it.
PARAMETERS
f_orm
: The form to analyze. REQUIRED.
RETURNS
- An array of
FLStats
: This is in the same order as the elements are declared in your form. The form is at element zero. Checkbox sets and radio sets are represented as a single object, located in this array, at the point of the first first element in the set.
SIGNATURE
gtAFLS(f_orm)
**/
function gtAFLS(f_orm) {
ciMissing(gtAFLS, "gtAFLS (XCMAX)", "f_orm", f_orm);
var aFLStats = new Array(1);
aFLStats[0] = new FLStats(f_orm);
//...and then each element within.
for(var i = 0; i < f_orm.elements.length; i++) {
//Passing in aFLStats is how we keep track of array
//elements (chk/rdo/slm) as a whole, rather than each
//array element in it.
var fls = new FLStats(f_orm[i], aFLStats[0], aFLStats);
if(fls.useThisFLS()) {
aFLStats[aFLStats.length] = fls;
}
}
return aFLStats;
}
/**
PUBLIC FUNCTION
After calling the cnstr (which analyzes an element or form), call this function to determine if this analysis resulted in an FLStats that should be regarded or discarded.
If this returns true, then use the object you just created via the cnstr, otherwise discared it.
var os = new FLStats(f_orm[i]);
if(os.useThisFLS()) {
//os should be kept.
} else {
//os should be discarded.
}
Elements that should be discarded include:
- The second or subsequent element in a radio set or checkbox set.
- An element not recognized by validate_form.js: "button", "submit", "reset", "hidden", ...
NOTE: This function can only be called once per object.
SIGNATURE
useThisFLS()
**/
function pb_useThisFLS() {
ciMissing(this.useThisFLS, "useThisFLS (XCMAX) [This function may only be called once per object, after which time this.bUseThisFLS is undefined.]", "this.bUseThisFLS", this.bUseThisFLS);
var b = this.bUseThisFLS;
this.bUseThisFLS = undefined;
return b;
}
/**
PUBLIC FUNCTION
Get the code for the provided attribute on this form/element.
PARAMETERS
s_attrNm
: The name of the attribute whose code you want. Provided directly to both gtCdAttrNm()
and gtAttrV()
.
RETURNS
this.gtCdAttrNm(s_attrNm) + " = " + [util_string.]gtCd4V(this.gtAttrV(s_attrNm)) + ";\n"
SIGNATURE
gtCd4Attr(s_attrNm)
**/
function pb_gtCd4Attr(s_attrNm) {
//util_string.gtCd4V()
return this.gtCdAttrNm(s_attrNm) + " = " + gtCd4V(this.gtAttrV(s_attrNm)) + ";\n";
}
/**
PUBLIC FUNCTION
Get the code for [this element].[provided attribute].
To get the code for the value, call [util_string.]gtCd4V(this.gtAttrV(s_attrNm))
.
PARAMETERS
s_attrNm
: The name of the attribute you want the code for. REQUIRED
RETURNS
this.sNm + "." + s_attrNm
when this.sType
equals 'form
'.
this.flsFrm.sNm + this.sAftrFrmNm + this.sNm + "." + s_attrNm + this.sAftrAttrNm
if otherwise.
SIGNATURE
gtCdAttrNm(s_attrNm)
**/
function pb_gtCdAttrNm(s_attrNm) {
ciMissing(this.gtCdAttrNm, "gtCdAttrNm (XCMAX)", "s_attrNm", s_attrNm);
if(this.sType == "form") {
return this.sNm + "." + s_attrNm;
} else {
return this.flsFrm.sNm + this.sAftrFrmNm + this.sNm + "." + s_attrNm + this.sAftrAttrNm;
}
}
/**
PUBLIC FUNCTION
Get the code for this FLStats' name.
PARAMETERS
s_attrNm
: The name of the attribute you want the name-code for. REQUIRED
RETURNS
this.sNm
when this.sType
equals 'form
'.
this.flsFrm.sNm + this.sAftrFrmNm + this.sNm + this.sAftrAttrNm
if otherwise.
SIGNATURE
gtCdFLSNm()
**/
function pb_gtCdFLSNm() {
if(this.sType == "form") {
return this.sNm;
} else {
return this.flsFrm.sNm + this.sAftrFrmNm + this.sNm + this.sAftrAttrNm;
}
}
/**
PUBLIC FUNCTION
Get the value of the attribute, whether or not it is actually associated to the element.
PARAMETERS
s_attrNm
: The name of the attribute whose value you want. REQUIRED
RETURNS
SIGNATURE
gtAttrVRaw(s_attrNm)
**/
function pb_gtAttrVRaw(s_attrNm) {
return eval(this.gtEvlCdLmntAttrNm(s_attrNm));
}
/**
PUBLIC FUNCTION
Has a certain attribute actually been associated to this element?
PARAMETERS
s_attrNm
: The name of the attribute to analyze for. REQUIRED
RETURNS
SIGNATURE
isAttrAssc2Lmnt(s_attrNm)
**/
function pb_isAttrAssc2Lmnt(s_attrNm) {
return df(this.gtAttrVRaw(s_attrNm));
}
var asSUB_RNG_ATTRS = ['dDecMin', 'dDecMax', 'iIntMin', 'iIntMax', 'iMinLength', 'iMaxLength', 'maxLength', 'iMCMin', 'iMCMax']; //XCMAX
/**
PUBLIC FUNCTION
Get the value of the attribute, whether or not it is actually associated to the element.
PARAMETERS
s_attrNm
: The name of the attribute whose value you want. REQUIRED and this attribute must be (a) actually be associated to this element, and (b) be one of the following :
sMsgFmt*
sMsgRequired
sMsgTxtDe
c
sMsgTxtEmail
sMsgTxtIn
t
sMsgBadLengt
h
sMsgMCRang
e
asGlobalBadSubStrs
bsNoBadSubStrs
asBadSubStrs
sMsgBadSubStr
bsGlobalTrimSpaces
bsDontTrimSpaces
bsTrimSpaces
- The standard HTML
MAXLENGTH
text attribute.
RETURNS
SIGNATURE
gtAttrV(s_attrNm)
**/
function pb_gtAttrV(s_attrNm) {
//validate_form.asVF_ATTRS and gtVRAIdx()
if(gtVRAIdx("gtAttrV", s_attrNm, asVF_ATTRS) == -1 &&//XCMAX
gtVRAIdx("gtAttrV", s_attrNm, asSUB_RNG_ATTRS) == -1) {//XCMAX
crsh("fls.gav1", this.gtAttrV, "gtAttrV (XCMAX): s_attrNm ('" + s_attrNm + "') is not a legal attribute. Must exist in either validate_form.asVF_ATTRS or fl_stats.asSUB_RNG_ATTRS.\n\n asVF_ATTRS=\n['" + asVF_ATTRS.join("', '") + "'])\n\nasSUB_RNG_ATTRS=\n(['" + asSUB_RNG_ATTRS.join("', '") + "'])");
} //XCMAX
if(!this.isAttrAssc2Lmnt(s_attrNm)) { //XCMAX
crsh("fls.gav2", this.gtAttrV, "gtAttrV (XCMAX): isAttrAssc2Lmnt(s_attrNm) equals false. s_attrNm='" + s_attrNm + "', this.sNm='" + this.sNm + "', this.sType='" + this.sType + "'.");
} //XCMAX
return this.gtAttrVRaw(s_attrNm);
}
/**
PUBLIC FUNCTION
Is the value of this element single- or multiple-valued?
RETURNS
SIGNATURE
isLmntVal1OrMore()
**/
function pb_isLmntVal1OrMore() {
return (!df(this.iTotOpts));
}
/**
PUBLIC FUNCTION
Get the singular value for this element.
Always use this function to get the value, although you must set the value manually, via the object, obj
.
May only be called when isLmntVal1OrMore()
returns true.
SIGNATURE
gtLmntValSnglr()
**/
function pb_gtLmntValSnglr() {
this.ciFrm1OrMore("gtLmntValSnglr", false);//XCMAX
//This element can have only one value, and is one of the
//following types:
// - text
// - textarea
// - radio
// - select-one
// - checkbox (with one element only)
var vValSnglr;
if(this.sType == "select-one" &&
this.obj.selectedIndex != -1) {
vValSnglr = this.obj.options[this.obj.selectedIndex].value;
} else if(this.sType == "radio") {
var rdo = eval(this.gtEvlCdObjNm());
for(var i = 0; i < rdo.length; i++) {
if(rdo[i].checked) {
vValSnglr = rdo[i].value;
break;
}
}
} else if(this.sType == "checkbox") {
//This is the only element in this checkbox set.
if(this.checked) {
vValSnglr = this.obj.value;
}
} else {
vValSnglr = this.obj.value;
}
return (vValSnglr == "")
? undefined
: vValSnglr;
}
/**
PUBLIC FUNCTION
Get the number of total options in this multiple-value element. May only be called when isLmntVal1OrMore() returns false.
SIGNATURE
gtLmntOptsTotal()
**/
function pb_gtLmntOptsTotal() {
this.ciFrm1OrMore("gtLmntOptsTotal", true);//XCMAX
return this.iTotOpts;
}
/**
PUBLIC FUNCTION
Get the number of total options in this multiple-valued form element.
This may only be called when this.sType
equals something other than 'form', and isLmntVal1OrMore() is false.
SIGNATURE
gtLmntOptsChosen()
**/
function pb_gtLmntOptsChosen() {
this.ciFrm1OrMore("gtLmntOptsChosen", true);//XCMAX
var iOptsChosen = 0;
if(this.sType == "checkbox" &&
this.flsFrm.obj.elements[this.sNm].length > 1) {
//Definitely more than one checkbox element in this
//checkbox set. Checkbox sets with only one element in it
//are single-valued.
for(var i = 0; i < this.iTotOpts; i++) {
if(this.flsFrm.obj.elements[this.sNm][i].checked) {
iOptsChosen++;
}
}
} else if(this.sType == "select-multiple") {
for(var i = 0; i < this.iTotOpts; i++) {
if(this.obj.options[i].selected) {
iOptsChosen++;
}
}
}
return iOptsChosen;
}
function pv_ciFrm1OrMore(s_callingFunc, b_1OrMore) {//XCMAX
if(this.sType == "form" || //XCMAX
this.isLmntVal1OrMore() == b_1OrMore) { //XCMAX
crsh("fls.cif1om", ciFrm1OrMore, s_callingFunc + " (XCMAX) ('" + this.sNm + "'): sType may not equal 'form', and/or b_1OrMore=" + b_1OrMore + " must equal isLmntVal1OrMore() (" + isLmntVal1OrMore() + ").");
} //XCMAX
} //XCMAX
/**
Analyze the form and create an FLStats for it. Called by the cnstr.
**/
function pv_gtFLS4Frm(f_orm) {
this.obj = f_orm;
this.sType = "form";
this.sAftrFrmNm = undefined;
this.sAftrAttrNm = undefined;
this.iTotOpts = undefined;
//This enforces the uniqueness restriction noted in the
//frm_frmLmnt parameter documentation of the FLStats
//constructor.
var bNameFound = false;
for(var i = 0; i < document.forms.length; i++) {
if(!bNameFound) {
if(document.forms[i].name == f_orm.name) {
//Found the first form having this form's name.
bNameFound = true;
}
//Still have yet to find a form having this form's
//name.
} else if(document.forms[i].name == f_orm.name) {//XCMAX
//A form with this name was already found. It is, but
//shouldn't be found again.
crsh("fls.gosff", this.gtFLS4Frm, "FLStats.constructor (XCMAX): The name of this form is '" + f_orm.name + "', but at least one other form on this page has that same name.");
}
}
}
/**
Analyze an element and create an FLStats for it. Called by the cnstr.
The heart of the FLStats object.
**/
function pv_gtLmntStats(frm_lmnt, a_prevFLS) {
this.sType = frm_lmnt.type;
//All the element types: text, textarea, radio,
//select-one, checkbox, select-multiple
this.iTotOpts = undefined;
if(this.sType == "checkbox" &&
this.flsFrm.obj.elements[frm_lmnt.name].length > 1) {
this.iTotOpts = this.flsFrm.obj.elements[frm_lmnt.name].length;
} else if(this.sType == "select-multiple") {
this.iTotOpts = frm_lmnt.options.length;
}
//If only one possible choice, then this.iTotOpts remain
//undefined.
if(this.sType == "radio" ||
(df(this.iTotOpts) && this.sType == "checkbox")) {
for(var i = 0; i < a_prevFLS.length; i++) {
if(a_prevFLS[i].sNm == frm_lmnt.name) {
//Already analyzed.
return false;
}
}
}
if(this.sType == "radio" ||
this.sType == "checkbox") {
this.obj = this.flsFrm.obj[frm_lmnt.name];
this.sAftrFrmNm = "['";
this.sAftrAttrNm = "']";
} else {
this.obj = frm_lmnt;
this.sAftrFrmNm = ".";
this.sAftrAttrNm = "";
}
//If this.iTotOpts is undefined, then this is a singular
//value element. Otherwise, it is a multiple-value object.
return true;
}
function pv_unassociateFalseBS(i_attrIdx) {
var sAttrNm = asVF_ATTRS[i_attrIdx];
if(this.isAttrAssc2Lmnt(sAttrNm) &&
this.gtAttrV(sAttrNm) == "false") {
eval(this.gtEvlCdLmntAttrNm(sAttrNm) + " = undefined;\n");
}
}
/**
PUBLIC FUNCTION
Get the name of this object-plus-the-provided-attribute, suitable for 'eval
'uation.
PARAMETERS
RETURNS
'document.' + this.sNm + '.' + s_attrNm
when this.sType
equals 'form
'
'document.' + this.flsFrm.sNm + this.sAftrFrmNm + this.sNm + '.' + s_attrNm + this.sAftrAttrNm
if otherwise.
SIGNATURE
gtEvlCdLmntAttrNm(s_attrNm)
**/
function pb_gtEvlCdLmntAttrNm(s_attrNm) {
ciMissing(this.gtEvlCdLmntAttrNm, "gtEvlCdLmntAttrNm (XCMAX)", "s_attrNm", s_attrNm);
return this.gtEvalCode(s_attrNm);
}
/**
PUBLIC FUNCTION
Get the name of this object, suitable for 'eval
'uation.
RETURNS
'document.' + this.sNm
when this.sType
equals 'form'
'document.' + this.flsFrm.sNm + this.sAftrFrmNm + this.sNm + this.sAftrAttrNm
if otherwise.
SIGNATURE
gtEvlCdObjNm()
**/
function pb_gtEvlCdObjNm() {
return this.gtEvalCode(undefined);
}
function pv_gtEvalCode(s_attrNm) {
var sAttrCd;
if(!df(s_attrNm)) {
sAttrCd = "";
} else {
sAttrCd = "." + s_attrNm;
}
if(this.sType == "form") {
//this.flsFrm may not exist if this is the
//cnstr!
return "document." + this.sNm + sAttrCd;
} else {
//this.flsFrm should exist, since the form should be
//created before any elements.
return "document." + this.flsFrm.sNm + this.sAftrFrmNm + this.sNm + sAttrCd + this.sAftrAttrNm;
}
}
/**********************************************************
**********************************************************
**********************************************************
E:\a_sandbox\validate_form_js\fl_stats.js...END
**********************************************************
**********************************************************
**********************************************************/
/**********************************************************
**********************************************************
**********************************************************
E:\a_sandbox\validate_form_js\vf_gtUsrErrCnt.js...START
**********************************************************
**********************************************************
**********************************************************/
/**
[BSD License. This license contains no advertising clause.]
validate_form.js: A comprehensive solution for validating the most common rules in HTML forms.
http://sourceforge.net/projects/validateformjs
Copyright (C) 2003-2005, Jeff Epstein
All rights reserved.
Modifications: No
Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met:
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* If modifications are made to source code then this license should indicate that fact in the "Modifications" section above.
* Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[NOTE: This license contains NO advertising clause.]
**/
/**
IMPORTANT NOTES
See validate_form_documentation.html for information.
- The words "XCSTD" and "XCMAX" (all caps) are critical even when part of a comment, string or variable name. These lines are deleted when compressed by BuildJS/BuildJS.java. It is also assumed there are no XCSTD/XCMAX on the very first *non-comment* or last lines of any file (which would be unlikely anyway). It won't crash (I think), but those first/last lines won't be eliminated (I think).
**/
/**
JS FILE OVERVIEW DOCUMENTATION
Analyzes a form's values, as provided by your users, and generates user-error messages as necessary.
**/
//Private variables...START
var cSS_DELIM = "\~";
var sSS_CURRLEN = 'CURRLEN';
var sSS_BOUND_MIN = 'RANGE_MIN';
var sSS_BOUND_MAX = 'RANGE_MAX';
var sSS_BSS_LIST = 'BSS_LIST';
var sSS_BSS_FOUND = 'BSS_FOUND';
var sSS_OPTS_TOT = 'OPTS_TOTAL';
var sSS_OPTS_CHSN = 'OPTS_CHOSEN';
var aFLStats = undefined;
//Private variables...END
//As defined in validate_form.js. This notifies all other
//code that this JavaScript file has indeed been loaded.
bLDD_GUEC = true;
/**
PUBLIC FUNCTION
Analyze the form, and return the number of (user or value) errors detected.
Error messages are stored in FLStats.sUsrErr
. When FLStats.sUsrErr
equals undefined
, that elemnt's value is legal. Otherwise, FLStats.sUsrErr
equals the specific error that should be presented to your user.
For example
Take this vf-configuration:
f_orm.your_integer.sMsgRequired = 'Your integer is required.';
f_orm.your_integer.sMsgTxtInt = 'Your integer must be between ~RANGE_MIN~ and ~RANGE_MAX~.';
f_orm.your_integer.iIntMin = 8;
f_orm.your_integer.iIntMax = 100;
...and say the value of your_integer is set to '6'. This is not in the defined range, so a_flStats[idx].sUsrErr
is set to:
'Your integer must be between 8 and 100.'
SIGNATURE
gtUsrErrCnt(a_flStats)
**/
function gtUsrErrCnt(a_flStats) {
//Start off with no errors.
var iTotalErrors = 0;
//"i = 1" because a_flStats[0] is the form, and therefore has no value.
for(var i = 1; i < a_flStats.length; i++) {
var fls = a_flStats[i];
//Assume no error. Eliminate previous ones.
fls.sUsrErr = undefined;
var bTxtPwd = (fls.sType == "text" ||
fls.sType == "password");
var bString = (bTxtPwd || fls.sType == "textarea");
if(bString) {
//Trimming has highest precedence.
trimStringLmnt(fls);
}
//Get the current value for this form elements.
var iOptsChosen;
var vValSnglr;
if(fls.isLmntVal1OrMore()) {
vValSnglr = fls.gtLmntValSnglr();
} else {
iOptsChosen = fls.gtLmntOptsChosen();
}
//If iOptsChosen is undefined, then this element is a
//singular-value element, even if vValSnglr is
//undefined. No value (or "") in a text box, for
//instance, is fine.
//Required has second-highest precedence.
if(hasRequiredError(fls, iOptsChosen, vValSnglr)) {
//The error message has been set into fls.sUsrErr.
iTotalErrors++;
continue;
}
//If we've reached here, then...
//...the value is not required and is...
// ...not missing
// ...missing
//...the value is required and is not missing
if((!df(vValSnglr) && !df(iOptsChosen)) ||
(df(iOptsChosen) && iOptsChosen == 0)) {
//(DON'T TOUCH OR RE-FORMAT THIS COMMENT)
//Nothing further to check, because there's no
//value. Go onto the next element.
//This is *not* an error, which is why
//"iTotalErrors++" is not here!
continue;
}
//This is not applicable with sif text/password
//elements, so it can be done before sif attributes are
//analyzed.
if(bString && hasStrLnError(fls, vValSnglr)) {
iTotalErrors++;
continue;
}
if(bTxtPwd) {
if(hasTxtPwdError(fls, vValSnglr)) {
iTotalErrors++;
continue;
}
} else if(fls.sType == "textarea") { //XCSTD (with below)
//Nothing txa-specific to check.
} else if(fls.sType == "radio" || fls.sType == "select-one") { //XCSTD (with below)
//Nothing rdo/sl1-specific to check.
} else if(fls.sType == "checkbox" || fls.sType == "select-multiple") {
//A checkbox set with one element is singular.
//A checkbox set with more than one element is multiple
//A radio set is always singular.
if(hasChkSlmError(fls, iOptsChosen, vValSnglr)) {
iTotalErrors++;
continue;
}
} else { //XCSTD (with two above)
crsh("gue1", gtUsrErrCnt, "gtUsrErrCnt (XCSTD): Unknown type: a_flStats[" + i + "].sType='" + fls.sType + "'.");
}
//Bad sub-strings has the lowest priority of all.
if(bString) {
if(hasBSSError(fls, vValSnglr)) {
iTotalErrors++;
continue;
}
}
}
return iTotalErrors;
}
/**
PUBLIC FUNCTION
This initializes validate_form.js
, as if getFormErrorMsgs()
were never called.
This does the following:
stAFLSvf(undefined, 'FORM NAME'); //For every form
//utility.js
bCrshd = false;
sCrshCd = undefined;
sCrshMsg = undefined;
fCrsh = undefined;
Some reasons to call this function
- A
validate_form.js
attribute (like "sMsgRequired
") has been added to/changed for/deleted from one of your form's elements.
- You've added a new option to a drop-down box (select-one) or changed the number of checkboxes/radio elements in a set.
- You've added or deleted an element from the form.
Some reasons that don't warrant a call to this function
- Changing values within a form, as your user will definitely do.
SIGNATURE
initVF()
**/
function initVF() {
for(var i = 0; i < aVfbc.length; i++) {
stAFLSvf(undefined, aVfbc[i].sFrmNm)
}
//utility.js
bCrshd = false;
sCrshCd = undefined;
sCrshMsg = undefined;
fCrsh = undefined;
}
/** PRIVATE FUNCTIONS...START **/
/** PRIVATE FUNCTIONS...START **/
/** PRIVATE FUNCTIONS...START **/
//Compatibility configuration...START
//documentation/unit_test/unit_tests.html#attribute_compatibility
//Every object-type recognized be validate_form.js
var cotFrm = new CmptblOTA(true, "form");
var cotTxt = new CmptblOTA(true, "text");
var cotPwd = new CmptblOTA(true, "password");
var cotTxa = new CmptblOTA(true, "textarea");
var cotRdo = new CmptblOTA(true, "radio");
var cotSl1 = new CmptblOTA(true, "select-one");
var cotChk = new CmptblOTA(true, "checkbox");
var cotSlm = new CmptblOTA(true, "select-multiple");
var asOBJ_TYPES = ["form", "text", "password", "textarea", "radio", "select-one", "checkbox", "select-multiple"];
var aCMPTBL_OBJ_TYPES = [cotFrm, cotTxt, cotPwd, cotTxa, cotRdo, cotSl1, cotChk, cotSlm];
//Every attribute type (except "sMsgTxt[SIFmt]" ones)
//recognized by validate_form.js
var ca_sMr = new CmptblOTA(false, "sMsgRequired");
var ca_sMtd = new CmptblOTA(false, "sMsgTxtDec");
var ca_sMte = new CmptblOTA(false, "sMsgTxtEmail");
var ca_sMti = new CmptblOTA(false, "sMsgTxtInt");
var ca_sMbl = new CmptblOTA(false, "sMsgBadLength");
var ca_sMmcr = new CmptblOTA(false, "sMsgMCRange");
var ca_asGbss = new CmptblOTA(false, "asGlobalBadSubStrs");
var ca_bsNbss = new CmptblOTA(false, "bsNoBadSubStrs");
var ca_asBss = new CmptblOTA(false, "asBadSubStrs");
var ca_sMbss = new CmptblOTA(false, "sMsgBadSubStr");
var ca_bsGts = new CmptblOTA(false, "bsGlobalTrimSpaces");
var ca_bsDts = new CmptblOTA(false, "bsDontTrimSpaces");
var ca_bsTs = new CmptblOTA(false, "bsTrimSpaces");
var aCMPTBL_ATTRS = [ca_sMr, ca_sMtd, ca_sMte, ca_sMti, ca_sMbl, ca_sMmcr, ca_asGbss, ca_bsNbss, ca_asBss, ca_sMbss, ca_bsGts, ca_bsDts, ca_bsTs];
var asVF_ATTRS = //idx
[ca_sMr.sNm, //0,
ca_sMtd.sNm, //1,
ca_sMte.sNm, //2,
ca_sMti.sNm, //3,
ca_sMbl.sNm, //4,
ca_sMmcr.sNm, //5,
ca_asGbss.sNm, //6,
ca_bsNbss.sNm, //7,
ca_asBss.sNm, //8,
ca_sMbss.sNm, //9,
ca_bsGts.sNm, //10,
ca_bsDts.sNm, //11,
ca_bsTs.sNm]; //12,
//
//(sMsgTxt[SIFmt], too: "sif")
//
//Define which attributes are compatible with a given
//object-type
//The length of ca4TxtPwd is used by stASIF()
var ca4TxtPwd = [ca_sMr, ca_sMtd, ca_sMte, ca_sMti, ca_sMbl, ca_bsNbss, ca_asBss, ca_sMbss, ca_bsDts, ca_bsTs];
var ca4ChkSlm = [ca_sMr, ca_sMmcr];
cotFrm.addGdAtts4OT([ca_bsGts, ca_asGbss]);
cotTxt.addGdAtts4OT(ca4TxtPwd); //sif
cotPwd.addGdAtts4OT(ca4TxtPwd); //sif
cotTxa.addGdAtts4OT([ca_sMr, ca_sMbl, ca_bsNbss, ca_asBss, ca_sMbss, ca_bsDts, ca_bsTs]);
cotRdo.addGdAtts4OT([ca_sMr]);
cotSl1.addGdAtts4OT([ca_sMr]);
cotChk.addGdAtts4OT(ca4ChkSlm);
cotSlm.addGdAtts4OT(ca4ChkSlm);
//Define which object-types are compatible with a given
//attribute.
var acotTxtPwd = [cotTxt, cotPwd];
var acotStrings = [cotTxt, cotPwd, cotTxa];
ca_sMr.stGoodOTs4Attr([cotTxt, cotPwd, cotTxa, cotRdo, cotSl1, cotChk, cotSlm]);
ca_sMtd.stGoodOTs4Attr(acotTxtPwd);
ca_sMte.stGoodOTs4Attr(acotTxtPwd);
ca_sMti.stGoodOTs4Attr(acotTxtPwd);
ca_sMbl.stGoodOTs4Attr(acotStrings);
ca_asBss.stGoodOTs4Attr(acotStrings);
ca_sMbss.stGoodOTs4Attr(acotStrings);
ca_bsDts.stGoodOTs4Attr(acotStrings);
ca_bsTs.stGoodOTs4Attr(acotStrings);
ca_bsNbss.stGoodOTs4Attr(acotStrings);
ca_sMmcr.stGoodOTs4Attr([cotChk, cotSlm]);
ca_asGbss.stGoodOTs4Attr([cotFrm]);
ca_bsGts.stGoodOTs4Attr([cotFrm]);
//Define which (other) attributes are *in*compatible with
//a given attribute.
//Adding [] is not possible, so commented out. Still
//listed though, for completeness.
//ca_sMr.addBdAtts4Att([]);
ca_sMtd.addBdAtts4Att([ca_sMte, ca_sMti]); //sif
ca_sMte.addBdAtts4Att([ca_sMtd, ca_sMti]); //sif
ca_sMti.addBdAtts4Att([ca_sMtd, ca_sMte, ca_sMbl]); //sif
ca_sMbl.addBdAtts4Att([ca_sMti]); //sif
//ca_sMmcr.addBdAtts4Att([]);
//ca_asGbss.addBdAtts4Att([]);
ca_bsNbss.addBdAtts4Att([ca_asBss, ca_sMbss]);
ca_asBss.addBdAtts4Att([ca_bsNbss]);
ca_sMbss.addBdAtts4Att([ca_bsNbss]);
//ca_bsGts.addBdAtts4Att([]);
ca_bsTs.addBdAtts4Att([ca_bsDts]); //sif
ca_bsDts.addBdAtts4Att([ca_bsTs]); //sif
//Compatibility configuration...START
function gtCOTA(a_cota, s_name) {
for(var i = 0; i < a_cota.length; i++) {
if(s_name == a_cota[i].sNm) {
return a_cota[i];
}
}
}
//Get form-value error messages...START
function gtMsgSSBounds(s_message, i_min, i_max) {
if(df(i_min)) {
s_message = gtMsgRplcSpclStr(s_message, cSS_DELIM, sSS_BOUND_MIN, i_min);
}
if(df(i_max) && i_max != -1) {
//For a text element, "MAXLENGTH" equals -1 when not defined (or bogus).
s_message = gtMsgRplcSpclStr(s_message, cSS_DELIM, sSS_BOUND_MAX, i_max);
}
return s_message;
}
function gtMsgRplcSpclStr(s_message, c_delimiter, s_toReplace, s_replaceWith) {
var sss = c_delimiter + s_toReplace + c_delimiter;
if(!df(s_message)) {
//Special case, when an error occured previously in the
//code, but throw didn't occur. If we don't do this,
//we'll get another throw, because the below will
//cause an "s_message has no properties"
//
s_message = "";
}
var iSSIdx = s_message.indexOf(sss);
if(iSSIdx != -1) {
return s_message.substring(0, iSSIdx) + s_replaceWith + s_message.substring((iSSIdx + sss.length), (s_message.length + 1));
} else {
return s_message;
}
}
function trimStringLmnt(fls_tpta) {
//This is a string element.
var v = fls_tpta.obj.value;
if(!df(v)) {
//No value to trim
return;
}
if(fls_tpta.isAttrAssc2Lmnt(ca_bsDts.sNm)) {
//Explicitely should not trim.
return;
}
if(fls_tpta.flsFrm.isAttrAssc2Lmnt(ca_bsGts.sNm) ||
fls_tpta.isAttrAssc2Lmnt(ca_bsTs.sNm)) {
//Trim it!
v = trmChr(' ', v);
fls_tpta.obj.value = trmChr('\t', v);
}
}
function hasRequiredError(fls_lmnt, i_optsChosen, v_valSnglr) {
ciMissing(hasRequiredError, "hasRequiredError (XCSTD)", "fls_lmnt", fls_lmnt);
if(fls_lmnt.sType == "form") { //XCSTD
crsh("guer1", hasRequiredError, "hasRequiredError (XCSTD): fls_lmnt.sType equals 'form'?! fls_lmnt.sNm='" + fls_lmnt.sNm + "'");
} //XCSTD
if(!fls_lmnt.isAttrAssc2Lmnt(ca_sMr.sNm)) {
//Missing is a non-issue. Good (false, no error)
return false;
}
//If missing, bad.
if((fls_lmnt.isLmntVal1OrMore() &&
!df(v_valSnglr)) ||
i_optsChosen == 0) {
fls_lmnt.sUsrErr = fls_lmnt.gtAttrV(ca_sMr.sNm);
return true;
}
//Not missing. Good (false, no error).
return false;
}
function hasTxtPwdError(fls_txtpwd, v_valSnglr) {
ciMissing(hasTxtPwdError, "hasTxtPwdError (XCSTD)", "fls_txtpwd", fls_txtpwd);
//It is assumed/expected that there is only one "sMsgTxt"
//variables associated to this text/password element.
if(fls_txtpwd.isAttrAssc2Lmnt(ca_sMte.sNm)) {
//util_string.isEml()
if(!isEml(fls_txtpwd.gtLmntValSnglr())) {
fls_txtpwd.sUsrErr = fls_txtpwd.gtAttrV(ca_sMte.sNm);
return true;
}
}
if(fls_txtpwd.isAttrAssc2Lmnt(ca_sMti.sNm)) {
return hasDecIntErr("false", fls_txtpwd, ca_sMti.sNm, "iIntMin", "iIntMax");
}
if(fls_txtpwd.isAttrAssc2Lmnt(ca_sMtd.sNm)) {
return hasDecIntErr("true", fls_txtpwd, ca_sMtd.sNm, "dDecMin", "dDecMax");
}
//sMsgTxt* (sif, not dec/email/int) attributes exist/were
//added at indexes 13 and up.
for(var i = 13; i < aCMPTBL_ATTRS.length; i++) {
if(fls_txtpwd.isAttrAssc2Lmnt(aCMPTBL_ATTRS[i].sNm)) {
//".sif" is set in stASIF()
var sStrpdAndValid = aCMPTBL_ATTRS[i].sif.gtFmtV(fls_txtpwd.obj.value);
if(df(sStrpdAndValid)) {
fls_txtpwd.obj.value = sStrpdAndValid;
return false;
} else {
fls_txtpwd.sUsrErr = fls_txtpwd.gtAttrV(aCMPTBL_ATTRS[i].sNm);
return true;
}
}
}
//None of these attributes were associated to this
//text/password element, so no error.
return false;
}
function hasDecIntErr(bs_decInt, fls_txtpwd, s_msgAttrNm, v_minBound, v_maxBound) {
var vMin = fls_txtpwd.gtAttrVRaw(v_minBound);
var vMax = fls_txtpwd.gtAttrVRaw(v_maxBound);
var vValue = fls_txtpwd.obj.value;
//util_string.isNum()
if(!isNum(fls_txtpwd.obj.value, bs_decInt) ||
(df(vMin) && vMin > vValue) ||
(df(vMax) && vMax < vValue)) {
fls_txtpwd.sUsrErr = gtMsgSSBounds(
fls_txtpwd.gtAttrV(s_msgAttrNm), vMin, vMax);
return true;
}
return false;
}
function hasStrLnError(fls_tpta, v_valSnglr) {
if(fls_tpta.sType != "text" && fls_tpta.sType != "password" &&
fls_tpta.sType != "textarea") {
//Only string elements have length.
return false;
}
//This is a string element
if(!fls_tpta.isAttrAssc2Lmnt(ca_sMbl.sNm)) {
//No value, so no bad length.
return false;
}
//Value, so possibly bad length.
var iCurrLen = fls_tpta.gtLmntValSnglr().length;
if(fls_tpta.isAttrAssc2Lmnt("iMinLength") &&
(iCurrLen < fls_tpta.gtAttrV("iMinLength"))) {
stBadLnMsg(fls_tpta, iCurrLen);
return true;
}
var iMx = fls_tpta.gtAttrVRaw("iMaxLength");
if(df(iMx) && iMx != -1 &&
(iCurrLen > iMx)) {
stBadLnMsg(fls_tpta, iCurrLen);
return true;
}
return false;
}
function stBadLnMsg(fls_tpta, i_currLen) {
var sErr = gtMsgRplcSpclStr(
fls_tpta.gtAttrV(ca_sMbl.sNm),
cSS_DELIM, sSS_CURRLEN,
i_currLen);
fls_tpta.sUsrErr = gtMsgSSBounds(sErr,
fls_tpta.gtAttrVRaw("iMinLength"),
fls_tpta.gtAttrVRaw("iMaxLength"));
}
function hasChkSlmError(fls_chkslm, i_optsChosen, v_valSnglr) {
if(!fls_chkslm.isAttrAssc2Lmnt(ca_sMmcr.sNm)) {
//The number of selected options doesn't matter.
return false;
}
//...oh yes it does...
var iMn = fls_chkslm.gtAttrVRaw("iMCMin");
var iMx = fls_chkslm.gtAttrVRaw("iMCMax");
if((df(iMn) &&
i_optsChosen < iMn) ||
(df(iMx) &&
iMx < i_optsChosen)) {
var sErr = gtMsgSSBounds(
fls_chkslm.gtAttrVRaw(ca_sMmcr.sNm), iMn, iMx);
sErr = gtMsgRplcSpclStr(sErr,
cSS_DELIM, sSS_OPTS_TOT, fls_chkslm.iTotOpts);
fls_chkslm.sUsrErr = gtMsgRplcSpclStr(sErr,
cSS_DELIM, sSS_OPTS_CHSN, fls_chkslm.gtLmntOptsChosen());
return true;
}
return false;
}
function hasBSSError(fls_tpta, v_valSnglr) {
if(!df(v_valSnglr)) { //XCSTD
crsh("gbsse1", hasBSSError, "hasBSSError (XCSTD): v_valSnglr is undefined?! I thought there was 'Nothing further to check' (seach for that in the code to see what this error relates to)...");
} //XCSTD
if(fls_tpta.flsFrm.isAttrAssc2Lmnt(ca_asBss.sNm)) {
//This element is exempt.
return false;
}
var asBSS;
if(fls_tpta.isAttrAssc2Lmnt(ca_asBss.sNm)) {
//The element's list has higher priority than the
//form's list, which is why this block comes before...
asBSS = fls_tpta.gtAttrV(ca_asBss.sNm)
} else if(fls_tpta.flsFrm.isAttrAssc2Lmnt(ca_asGbss.sNm)) {
//...this one.
asBSS = fls_tpta.flsFrm.gtAttrV(ca_asGbss.sNm)
} else {
//No bad sub strings are defined.
return false;
}
//There are illegal sub-strings.
for(var i = 0; i < asBSS.length; i++) {
if(v_valSnglr.indexOf(asBSS[i]) != -1) {
var sErr = gtMsgRplcSpclStr(
fls_tpta.gtAttrV(ca_sMbss.sNm),
cSS_DELIM, sSS_BSS_LIST,
"['" + asBSS.join("', '") + "']");
fls_tpta.sUsrErr = gtMsgRplcSpclStr(sErr,
cSS_DELIM, sSS_BSS_FOUND,
asBSS[i]);
return true;
}
}
//No bad sub-strings found in the value.
return false;
}
//Get user error messages...END
/** PRIVATE FUNCTIONS...END **/
/** PRIVATE FUNCTIONS...END **/
/** PRIVATE FUNCTIONS...END **/
/**********************************************************
**********************************************************
**********************************************************
E:\a_sandbox\validate_form_js\vf_gtUsrErrCnt.js...END
**********************************************************
**********************************************************
**********************************************************/
/**********************************************************
**********************************************************
**********************************************************
E:\a_sandbox\validate_form_js\cmptbl_ot_a.js...START
**********************************************************
**********************************************************
**********************************************************/
/**
[BSD License. This license contains no advertising clause.]
validate_form.js: A comprehensive solution for validating the most common rules in HTML forms.
http://sourceforge.net/projects/validateformjs
Copyright (C) 2003-2005, Jeff Epstein
All rights reserved.
Modifications: No
Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met:
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* If modifications are made to source code then this license should indicate that fact in the "Modifications" section above.
* Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[NOTE: This license contains NO advertising clause.]
**/
function pb_addGdAtts4OT(a_cvfAttribute) {
this.addCVFAttrs("addGdAtts4OT", true, a_cvfAttribute);
}
function pb_addBdAtts4Att(a_cvfAttribute) {
this.addCVFAttrs("addBdAtts4Att", false, a_cvfAttribute);
}
function pv_addCVFAttrs(s_callingFunc, b_objTypeOrAttr, a_cvfAttribute) {
this.add2RA(s_callingFunc, b_objTypeOrAttr, this.aACAttrs_G4OT_B4A, a_cvfAttribute);
}
function pb_stGoodOTs4Attr(a_cvfAttribute) {
if(this.aCObjTypes_G4A.length > 1) { //XCMAX
crsh("cota.sgot4a1", this.stGoodOTs4Attr, "stGoodOTs4Attr (XCMAX): this.aCObjTypes_G4A.length=" + this.aCObjTypes_G4A.length + ". Can only call this function once. Note the name of this function starts 'st' (meaning 'set'), not 'add'.");
} //XCMAX
this.add2RA("stGoodOTs4Attr", false, this.aCObjTypes_G4A, a_cvfAttribute);
}
function pb_add2RA(s_callingFunc, b_objTypeOrAttr, a_dest, a_cvfAttribute) {
cibRA(s_callingFunc + " (XCMAX)", "a_cvfAttribute", a_cvfAttribute);
if(b_objTypeOrAttr != this.bOTorA) { //XCMAX
crsh("cota.cincvfa", this.add2RA, s_callingFunc + " (XCMAX): This function is only applicable for " + (b_objTypeOrAttr?"object-types":"vf-attributes") + ". This object represents " + (this.bOTorA?"object-types":"vf-attributes") + ".");
} //XCMAX
for(var i = 0; i < a_cvfAttribute.length; i++) {
a_dest[a_dest.length] = a_cvfAttribute[i];
}
}
function pb_hasAttr(s_attribute) {
ciMissing(this.hasAttr, "hasAttr (XCMAX)", "s_attribute", s_attribute);
for(var i = 0; i < this.aACAttrs_G4OT_B4A.length; i++) {
if(s_attribute == this.aACAttrs_G4OT_B4A.sNm) {
return true;
}
}
return false;
}
function pb_hasOT(s_objType) {
ciMissing(this.hasOT, "hasOT (XCMAX)", "s_objType", s_objType);
for(var i = 0; i < this.aCObjTypes_G4A.length; i++) {
if(s_objType == this.aCObjTypes_G4A[i].sNm) {
return true;
}
}
return false;
}
/**
Constructor: Create a new CmptblOTA.
b_objTypeOrAttr If true, then this represents an object type. If false, an attribute.
**/
function CmptblOTA(b_objTypeOrAttr, s_name) {
ciMissing(CmptblOTA, "CmptblOTA (XCMAX)", "b_objTypeOrAttr", b_objTypeOrAttr);
ciMissing(CmptblOTA, "CmptblOTA (XCMAX)", "s_name", s_name);
if(s_name.length < 1) { //XCMAX
crsh("coa.cnstr1", CmptblOTA, "CmptblOTA.constructor (XCMAX): s_name is zero characters in length.");
} //XCMAX
this.sNm = s_name;
this.bOTorA = b_objTypeOrAttr;
this.aCObjTypes_G4A = [];
this.stGoodOTs4Attr = pb_stGoodOTs4Attr;
//Both object-types and attributes keep track of attributes,
//for one reason or another.
this.aACAttrs_G4OT_B4A = [];
this.addBdAtts4Att = pb_addBdAtts4Att;
this.addGdAtts4OT = pb_addGdAtts4OT;
this.addCVFAttrs = pv_addCVFAttrs;
this.add2RA = pb_add2RA;
this.hasAttr = pb_hasAttr;
this.hasOT = pb_hasOT;
//For ca-s that are representing SIFmt attributes.
//Used in hasTxtPwdError()
//".sif" is set in stASIF()
this.sif = undefined;
}
/**********************************************************
**********************************************************
**********************************************************
E:\a_sandbox\validate_form_js\cmptbl_ot_a.js...END
**********************************************************
**********************************************************
**********************************************************/
/**********************************************************
**********************************************************
**********************************************************
E:\a_sandbox\validate_form_js\util_array.js...START
**********************************************************
**********************************************************
**********************************************************/
/**
[BSD License. This license contains no advertising clause.]
validate_form.js: A comprehensive solution for validating the most common rules in HTML forms.
http://sourceforge.net/projects/validateformjs
Copyright (C) 2003-2005, Jeff Epstein
All rights reserved.
Modifications: No
Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met:
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* If modifications are made to source code then this license should indicate that fact in the "Modifications" section above.
* Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[NOTE: This license contains NO advertising clause.]
**/
/**
JS FILE OVERVIEW DOCUMENTATION
Random, standalone functions for array analysis.
**/
/**
PUBLIC FUNCTION
Get the array index, at which the (first instance of the) desired value exists.
PARAMETERS
s_callingFunc
: The function calling this, for potential error messages only.
v_alue
: The value to find in a_value
a_value
: The value array to search for v_alue
in. Must be a good array
RETURNS
- Array index of
a_value
Of the first element equal to v_alue
.
- -1 when no
a_value
element equals v_alue
.
SIGNATURE
gtVRAIdx(s_callingFunc, v_alue, a_value)
**/
function gtVRAIdx(s_callingFunc, v_alue, a_value) {
cibRA(s_callingFunc + " (XCMAX) [NOTE THAT THERE ARE THREE PARAMETERS, THE FIRST BEING THE 'CALLING FUNCTION']", "a_value", a_value);
for(var i = 0; i < a_value.length; i++) {
if(v_alue == a_value[i]) {
return i;
}
}
return -1;
}
/**
PUBLIC FUNCTION
Is the desired value in the ordered-ascending array of values?
PARAMETERS
v_alue
: The value to find in a_value
. REQUIRED
a_value
: The ordered-ascending value array, to search for v_alue
in. Must be a good array. It is assumed that it is ordered-ascending (a..z). If not, this function will behave unpredictably.
RETURNS
- true when an element in
a_value
equals v_alue
.
- false if not.
SIGNATURE
isInAscRA(v_alue, a_value)
**/
function isInAscRA(v_alue, a_value) {
cibRA("isInAscRA (XCMAX)", "a_value", a_value);
for(var i = 0; i < a_value.length; i++) {
if(v_alue < a_value[i]) {
return false;
}
if(v_alue == a_value[i]) {
return true;
}
}
return false;
}
/**
PUBLIC FUNCTION
Is the provided object an array?
This concept comes from Kas Thomas, at
http://www.planetpdf.com/mainpage.asp?webpageid=1144
PARAMETERS
o_potentialArray
: The object to analyze for array-ness. REQUIRED.
RETURNS
- true when
o_potentialArray
is an array.
- false if not.
SIGNATURE
isRA(o_potentialArray)
**/
function isRA(o_potentialArray) {
ciMissing(isRA, 'util_array.isRA (XCMAX)', 'o_potentialArray', o_potentialArray);
if(typeof o_potentialArray != 'object') {
return false;
}
//It is definitely an object.
return (o_potentialArray.constructor.toString().match(/array/i) != null);
}
/**********************************************************
**********************************************************
**********************************************************
E:\a_sandbox\validate_form_js\util_array.js...END
**********************************************************
**********************************************************
**********************************************************/
/**********************************************************
**********************************************************
**********************************************************
E:\a_sandbox\validate_form_js\util_string.js...START
**********************************************************
**********************************************************
**********************************************************/
/**
[BSD License. This license contains no advertising clause.]
validate_form.js: A comprehensive solution for validating the most common rules in HTML forms.
http://sourceforge.net/projects/validateformjs
Copyright (C) 2003-2005, Jeff Epstein
All rights reserved.
Modifications: No
Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met:
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* If modifications are made to source code then this license should indicate that fact in the "Modifications" section above.
* Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[NOTE: This license contains NO advertising clause.]
**/
/**
JS FILE OVERVIEW DOCUMENTATION
Random functions for creating, manipulating and analyzing strings.
**/
/**
PUBLIC FUNCTION
Is the provided string a legal number?
PARAMETERS
s_potential
: The string to analyze. REQUIRED
bs_decimalAllowed
: Is the potential number allowed to be a decimal? If 'true', then yes. If 'false', no. REQUIRED.
RETURNS
true
if...
- s_potential is a legal integer (regardless the value of bs_decimalAllowed). A legal integer is a string that...
- ...contains one or more zeros. Note that 0 equals 0000 equals 0000000000 equals ...
- ...starts with zero or one dashes (indicating negative), followed by one or more digits (0-9), where at least one is greater than zero.
- If bs_decimalAllowed is 'true' and s_potential is a legal decimal. A legal decimal is a string that...
- ...is an integer.
- ...starts with zero or one dashes (indicating negative) followed by zero or more digits, followed by a decimal point ('.'), followed by *one* or more digits.
Note that s_potential is checked to be an integer first. If it is, then true is returned, regardless the value of bs_decimalAllowed. If the string is an integer, it is not checked, specifically, to see if it's a decimal. Hence, the description of a legal decimal number says "a decimal point" instead of "zero or one decimal points".
false
if otherwise-
LEGAL EXAMPLES (both integers and decimals)
-1
0
1
-50
8750328754
00008750328754
08750328754
-487584758475235
-0000000487584758475235
-0487584758475235
ILLEGAL EXAMPLES (both integers and decimals)
4875847-58475235
487584758475235-
[EMPTY_STRING]
a
0-
-0
Not a number!!!
Some 123 numbers 456
123 456
-0.0
-.0
-0.000000
-.000000
1.
.
LEGAL EXAMPLES (decimals, but only after it is determined that the value is *not* an integer)
1.1
1.000830847018374
058763408562473.01837486564417308746
.1
.0
.01
-1.0
SIGNATURE
isNum(s_potential, bs_decimalAllowed)
**/
function isNum(s_potential, bs_decimalAllowed) {
ciMissing(isNum, 'util_string.isNum [XCMAX]', 's_potential', s_potential);
cibBoolStr('util_string.isNum [XCMAX]', 'bs_decimalAllowed', bs_decimalAllowed);
if(s_potential.length < 1) {
return false;
}
if(s_potential == '-') {
//A negative sign only makes no sense.
return false;
}
if(/^-[0]+$/.test(s_potential)) {
//Negative zero makes no sense.
return false;
}
if(/^[0]+$/.test(s_potential)) {
//Zero is a legal number:
//0 == 0000000000000 == 000
return true;
}
//It is definitely not zero.
//^ The start of the line.
//[-]{0,1} Zero or one dashes.
//[0-9]+ One or more of any digit.
//$ The end of the line.
if(/^[-]{0,1}[0-9]+$/.test(s_potential)) {
//No matter what, this is valid. This is a leagal integer
//and decimal.
return true;
}
//It's not an integer...
if(bs_decimalAllowed == 'false') {
//...but it must be.
return false;
}
//...and that's okay. It might be a decimal
//Due to precision:
//10.0000000000001 is legal (12 zeros)
//10.00000000000001 is not (13 zeros)
//^ The start of the line.
//[-]{0,1} Zero or one dashes.
//[0-9]* Zero or more digits.
//[.] A decimal point.
//[0-9]+ One or more digits.
//$ The end of the line.
if(/^[-]{0,1}[0-9]*[.][0-9]+$/.test(s_potential)) {
//It is a "raw" decimal. The only thing that would make
//this illegal is if it were -0.0 or -.0, or -0.0000 or
//-.0000 or ...
return !(/^-0*[.]0+$/.test(s_potential));
}
//It is not a legal decimal number.
return false;
}
/**
PUBLIC FUNCTION
Is the provided string a properly-formatted email address?
A 'bad' email has any of the following characteruistics:
- Is
undefined
or zero characters in length.
- Contains no spaces (' '), slashes ('/' or '\\'), or commas (',').
- Has a dot ('.') immediately followed or preceded by at-sign ('@').
- First or last character is a dot or at-sign.
- Contains zero or more than one at-sign.
- No dot (non-immediately) follows the at-sign
PARAMETERS
s_potentialEmail
: The string to check for email-ness. REQUIRED.
RETURNS
true
if s_potentialEmail
false
if not.
GOOD EXAMPLES
bla@bloo.com
bla.blee@bloo.blay.com
bla_blee@bloo_blay.com
x@x.x
x.x.x.x.x.@x.x.x.x.x.x.x.x.x
BAD EXAMPLES
x
@
.
@@
..
@.
.@
bla @ bloo . com
[A SPACE]
bla@bloo.com
bla@bl oo.com
bla.@.bloo.com
bla@bloo.combla@bloo.com
SIGNATURE
isEml(s_potentialEmail)
**/
function isEml(s_potentialEmail) {
if(!df(s_potentialEmail) || //XCMAX
s_potentialEmail.length < 1) {//XCMAX
crsh("us.ie1", isEml, "isEml (XCMAX): s_potentialEmail must be defined, and at least one character in length.");
} //XCMAX
if(s_potentialEmail.indexOf(" ") != -1 ||
s_potentialEmail.indexOf("/") != -1 ||
s_potentialEmail.indexOf("\\\\") != -1 ||
s_potentialEmail.indexOf(",") != -1) {
//A space, slash or comma was found.
return false;
}
if(/[@.][@.]/.test(s_potentialEmail)) {
//An @ or dot is followed by an @ or dot.
return false;
}
if(/^[@.]/.test(s_potentialEmail)) {
//The first character is an @ or dot.
return false;
}
if(/[@.]$/.test(s_potentialEmail)) {
//The last character may not be an @ or dot.
return false;
}
if(!/^[^@]+@[^@]+$/.test(s_potentialEmail)) {
//Only one @ allowed
// (Negative of:
// Must have one or more non-@ starting the line,
// exactly one @, and then
// one or more non-@ ending the line.)
return false;
}
//There is exactly one @.
if(!/@.*[.]/.test(s_potentialEmail)) {
//At least one dot must follow the (single) @.
return false;
}
//At least one dot follows the @. We already determined
//above that it does not immediately follow it,
//No negative conditions were met. This is a legal email address.
//Cool, eh? : )
return true;
}
/**
PUBLIC FUNCTION
Trim all contiguous instances of the provided character from the ends of a string
PARAMETERS
c_harToTrim
: The character to trim off of s_tring
. REQUIRED and must be a character/string-of-length-one.
s_tring
: The string to trim. REQUIRED.
SIGNATURE
trmChr(c_harToTrim, s_tring)
**/
function trmChr(c_harToTrim, s_tring) {
if(!c_harToTrim || c_harToTrim.length != 1) {//XCMAX
crsh("us.tc1", trmChr, "us.trmChr (XCMAX): c_harToTrim must be provided, and must be exactly one character in length. Currently '" + c_harToTrim + "'.");
} //XCMAX
ciMissing(trmChr, 'us.trmChr [XCMAX]', 's_tring', s_tring);
var i = 0;
var iStartingSpaces = 0;
while(s_tring.substring(i, (i + 1)) == c_harToTrim) {
iStartingSpaces++;
i++;
}
if(iStartingSpaces == s_tring.length) {
return "";
}
i = 0;
var iEndingSpaces = 0;
while(s_tring.substring((s_tring.length - i), (s_tring.length - (i + 1))) == c_harToTrim) {
iEndingSpaces++;
i++;
}
if(iStartingSpaces == 0 && iEndingSpaces == 0) {
return s_tring;
}
return s_tring.substring(iStartingSpaces, (s_tring.length - iEndingSpaces));
}
/**
PUBLIC FUNCTION
Get the provided value returned as a string, and suitable for insertion into code.
PARAMETERS
s_value
: The value to code-ize.
RETURNS
"undefined"
when s_value
is undefined.
s_value
when s_value
is a number.
"['" + s_value.join("', '") + "']"
when s_value
is an array.
"'" + s_value + "'"
if otherwise.
- Not sure if there's a definitive way to return a boolean without quotes... So for now, you'll always get a boolean value returned as if it were a string.
SIGNATURE
gtCd4V(s_value)
**/
function gtCd4V(s_value) {
if(!df(s_value)) {
return "undefined";
//util_string.isNum()
} else if(isNum(s_value, "true")) {
return s_value;
//util_array.isRA()
} else if(isRA(s_value)) {
return "['" + s_value.join("', '") + "']";
} else {
//This is a boolean string or plain string.
return "'" + s_value + "'";
}
}
/**********************************************************
**********************************************************
**********************************************************
E:\a_sandbox\validate_form_js\util_string.js...END
**********************************************************
**********************************************************
**********************************************************/
/**********************************************************
**********************************************************
**********************************************************
E:\a_sandbox\validate_form_js\crash_if.js...START
**********************************************************
**********************************************************
**********************************************************/
/**
[BSD License. This license contains no advertising clause.]
validate_form.js: A comprehensive solution for validating the most common rules in HTML forms.
http://sourceforge.net/projects/validateformjs
Copyright (C) 2003-2005, Jeff Epstein
All rights reserved.
Modifications: No
Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met:
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* If modifications are made to source code then this license should indicate that fact in the "Modifications" section above.
* Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[NOTE: This license contains NO advertising clause.]
**/
/**
JS FILE OVERVIEW DOCUMENTATION
Functionality to 'crsh' when certain conditions are met.
All 'crash-if' functionality is grouped into this single file, to facilitate compression. For...
- ...'no' and 'standard' compression, crash-if functionality is used, and therefore this file is imported normally.
- ...'maximum' compression, crash-if functionality is not used at all, and therefore this file is not imported.
Public variables
bCRSH_ALRT
: Assumed to equal either true
or false
. See crsh() for how this is used.
bCRSH_DGNSTCS
: Assumed to equal either true
or false
. See crsh() for how this is used.
bCRSH_THROW
: Assumed to equal either true
or false
. See crsh() for how this is used.
**/
//[crsh() ids used in this js file: 1..4]
//Global variables...START
//As defined in validate_form.js. This notifies all other
//code that this JavaScript file has indeed been loaded.
bLDD_CI = true;
//Initialized in validate_form.js
//A secret public global variable. For testing purposes, you
//may want to avoid re-displaying the error after the alert
//box (within H1 tags). This gives you access to the error id
//
//bCRSH_ALRT: If 'true', then an alert box is displayed
//when the crash function is called. If 'false', no alert box
//is displayed. Should default to 'true'.
bCRSH_ALRT = true;
//bCRSH_DGNSTCS: If 'true', then the error message is
//displayed on a new web page, to make it truly clear that an
//error occured. If 'false', the error message is not
//displayed on a new page. Should default to 'true'.
bCRSH_DGNSTCS = true;
//bCRSH_THROW
bCRSH_THROW = true;
//This is automatically manipulated by this js file. It is private
//and should never be altered.
var bCrshd = false;
//The id of the error.
var sCrshCd = undefined;
var fCrsh = undefined;
//The full text of the error.
var sCrshMsg = undefined;
//Global variables...END
/**
PUBLIC FUNCTION
Present an error message in an alert box, and also redisplay the provided error message to screen, on a new web page, surrounded by H1 tags.
This function is intended for fatal programming errors, not users-put-a-bad-value-in-the-form errors.
PARAMETERS
s_code
: Code that should help you identify the specific error. REQUIRED, and may not equal 0 or empty string.
f_unc
: A reference to the function in which the error is occurring. There are differences between browsers which may or may not print out all the desired f_unc attributes.
s_callingFuncAndError
: The function name, followed by the error message.
Actions taken by this function, in order
- If
bCRSH_ALRT
equals true, then an alert box is displayed with s_callingFuncAndError
- If
bCRSH_DGNSTCS
equals true, then you are redirected to a 'new' page, in which s_callingFuncAndError
, along with a boat-load of diagnostics, are prominently displayed. Although execution is not truly interrupted, this should be significant enough to alert the programmer to an error. I'm notincing that redisplay is not 100% consistent when Venkman (the JavaScript Debugger) is installed.
- If
bCRSH_THROW
is true, then
throw "DEVELOPER ERROR (code=' + s_code + ') in ' + s_callingFuncAndError
When false, after the initial error is displayed, unpredictable behavior should be expected.
FOR EXAMPLE
Take this code...
function theCallingFunction() {
theFunctionItself(8, 27, undefined, "Here's a string parameter.");
}
function theFunctionItself(i_1, i_2, v_ariable, s_tring) {
crsh("tfi1", theFunctionItself, "theFunctionItself: You really shouldn't do that! :' (");
}
...run theCallingFunction()
...
...and you'll get this alert()
box (if bCRSH_ALRT
is true)...
...and this diagnostics page (if bCRSH_DGNSTCS
is true).
The error I'm getting makes no sense! Some tips...
- Check the JavaScript Console. It may have a totally unrelated error that occured before the 'crsh'.
- You can't load a file (via
document.writeln('<SCRIPT SRC...
) from a function being called in another tag's attribute. For example, body.onLoad
.
- When a JavaScript block (
<SCRIPT LANGUAGE=...>//<!--...--></SCRIPT>
) has an error, it's as if the entire block doesn't exist. Subsequent blocks may crash for bizarre reasons, because the code in the dependant block was never executed.
SIGNATURE
crsh(s_code, f_unc, s_callingFuncAndError)
**/
function crsh(s_code, f_unc, s_error) {
if(!df(f_unc)) {
return alert("ERROR in utility.crsh: f_unc is undefined. [crsh.caller=" + crsh.caller.name + ", s_code='" + s_code + "', s_error='" + s_error + "']");
}
if(!df(f_unc.arguments)) {
return alert("ERROR in utility.crsh: f_unc.arguments is undefined. Make sure f_unc is a function reference. [crsh.caller=" + crsh.caller.name + ", s_code='" + s_code + "', s_error='" + s_error + "']");
}
if(!s_code) {
return alert("ERROR in utility.crsh: s_code is required and must not equal zero or empty string. [crsh.caller=" + crsh.caller.name + ", f_unc='" + f_unc + "', s_error='" + s_error + "']");
}
var sHdr = "u.crsh() ERROR. ";
var sFncNm = "Function: " + f_unc.name + "()";
var sCode = "Code: " + s_code;
var sClrNm = "Caller: ";
if(df(f_unc.caller)) {
//This block cannot be a ()?: line, because you'll get
//a "f_unc.caller has no properties" exception when this
//error is from a top-level function call.
sClrNm += f_unc.caller.name + "()"
} else {
sClrNm += "[TOP LEVEL CALL. Called by the document itself]";
}
var sCrshClr = "crsh() caller: " + crsh.caller.name;
var sArgs = "";
var aFrgs = f_unc.arguments;
if(!isRA(aFrgs)) {
sArgs = "COULD NOT DETERMINE ARGUMENTS. f_unc.arguments is not of type 'array'. WHY?!";
} else {
for(var i = 0; i < aFrgs.length; i++) {
sArgs += i + " [" + aFrgs[i] + "]\n";
}
}
sArgs = "Argument(s):\n" + sArgs;
//This must precede the "wrt" line. Otherwise you'll get
//a "not defined" exception for either getEMsg() or
//bCRSH_ALRT...START
var sLrt = sHdr + sCode + "\nbCRSH_DGNSTCS=" + bCRSH_DGNSTCS + " bCRSH_ALRT=" + bCRSH_ALRT + " bCRSH_THROW=" + bCRSH_THROW + "\n";
if(bCRSH_DGNSTCS) {
sLrt += "\n(About to write this error and code to the document)";
} else if(bCRSH_ALRT && window.location.hash.length > 0) {
if(bCRSH_THROW) {
sLrt += "\n[[[ NOTE: The page may reload to '" + window.location.hash + "', and form values may revert to their defaults. ANYONE KNOW WHY THIS RELOADS IN UNPREDICTABLE LOCATIONS???? ]]]";
} else {
sLrt += "\n[[[ NOTE: bCRSH_THROW equals false. Unpredictable behavior may follow this dialog... ]]]";
}
}
sLrt += "\n------------------------" +
"\n" + s_error +
"\n---------------------\n" + sFncNm +
"\n" + sClrNm +
"\n" + sCrshClr;
//For debugging purposes.
sCrshCd = s_code;
sCrshMsg = sLrt;
fCrsh = f_unc;
if(bCRSH_ALRT) {
alert(sLrt);
}
//This must precede the "wrt" line. Otherwise you'll get
//a "not defined" exception for either getEMsg() or
//bCRSH_ALRT...END
var sDgnstcs;
if(bCRSH_DGNSTCS) {
var sb = "\n
";
var sTop = "\n" + sHdr + sCode + "...";
var sBtm = " |
";
sDgnstcs = sTop + "START" + sBtm +
"" + s_error + "
\n" +
"Details
\n" + sCode + sb + sFncNm + sb + sClrNm + sb + sCrshClr + "
\n" + sArgs + "
\n" +
"The function
\n" + f_unc + "
\nThe calling function
\n" + f_unc.caller + "
\n" +
sTop + "END\n" + sBtm;
}
//Divided into two functions, which for some reason seems to
//prevent errors.
if(bCRSH_THROW) {
crshAndThrow(sDgnstcs, sLrt);
} else {
crshNoThrow(sDgnstcs);
}
}
function crshAndThrow(s_dgnstcs, s_throwMsg) {
if(bCRSH_DGNSTCS) {
wrt(s_dgnstcs);
}
throw s_throwMsg;
}
function crshNoThrow(s_dgnstcs) {
if(bCRSH_DGNSTCS) {
wrt(s_dgnstcs);
}
}
/**
PUBLIC FUNCTION
Basic Crash if a required parameter is provided.
When the parameter is provided, do nothing.
PARAMETERS
f_calling
: The function object, calling this function. For potential error diagnostics only.
s_callingFunc
: The function calling this one, for potential error messages only.
s_variableName
: The name of bs_shouldBe, for potential error messages only.
v_required
: The required variable analyzed for existence.
SIGNATURE
ciMissing(f_calling, s_callingFileFunc, s_varName, v_required)
**/
function ciMissing(f_calling, s_callingFileFunc, s_varName, v_required) {
if(!df(v_required)) {
crsh("u.cim1", f_calling, s_callingFileFunc + ': Required parameter ' + s_varName + ' is undefined.');
}
}
/**
PUBLIC FUNCTION
Intended for utility.js
. Crash if the provided BooleanString is undefined or bogus.
When the BooleanString is provided and valid, do nothing.
A BooleanString is considerd valid (good) when it is both defined and a string equal to 'true
' or 'false
'.
PARAMETERS
s_callingFunc
: The function calling this one, for potential error messages only.
s_bsName
: The name of bs_shouldBe, for potential error messages only.
bs_shouldBe
: The variable analyzed for BooleanString-ness.
SIGNATURE
cibBoolStr(s_callingFunc, s_bsName, bs_shouldBe)
**/
function cibBoolStr(s_callingFunc, s_bsName, bs_shouldBe) {
ciMissing(cibBoolStr, "u.cibBoolStr (s_callingFunc='" + s_callingFunc + "', s_bsName='" + s_bsName + "')", "bs_shouldBe", bs_shouldBe);
if(bs_shouldBe == 'true' || bs_shouldBe == 'false') {
//It's all good.
return;
}
crsh("u.cibbs1", cibBoolStr, s_callingFunc + ": " + s_bsName + " must be a *string* equal to either 'true' or 'false'. EXTRA INFO: bs_shouldBe.toString()='" + bs_shouldBe.toString() + "', bs_shouldBe.type='" + bs_shouldBe.type + "' , value='" + bs_shouldBe + "'.");
}
/**
PUBLIC FUNCTION
Intended for fl_stats.js
. Crash if the provided array of FLStats
is bogus. Otherwise do nothing..
'Good' is defined as not bad and that every element is an FLStats
.
PARAMETERS
s_callingFunc
: The function calling this one, for potential error messages only.
s_aosName
: The name of a_flStats, for potential error messages only.
a_flStats
: The required variable analyzed.
SIGNATURE
cibAFLS(s_callingFunc, s_aosName, a_flStats)
**/
function cibAFLS(s_callingFunc, s_aosName, a_flStats) {
cibRA(s_callingFunc, s_aosName, a_flStats);
for(var i = 0; i < a_flStats.length; i++) {
ciNotFLStats(s_callingFunc, s_aosName + "[" + i + "]", a_flStats[i]);
}
}
/**
PUBLIC FUNCTION
Intended for fl_stats.js
. Crash if the provided variable is FLStats
is bogus. Otherwise do nothing..
'Good' is defined as
!(!df(v_shouldBeFLS.type) ||
v_shouldBeFLS.type != "FLStats")
.
PARAMETERS
s_callingFunc
: The function calling this one, for potential error messages only.
s_flsName
: The name of v_shouldBeFLS, for potential error messages only.
v_shouldBeFLS
: The variable to be analyzed for FLStats-ness.
SIGNATURE
ciNotFLStats(s_callingFunc, s_flsName, v_shouldBeFLS)
**/
function ciNotFLStats(s_callingFunc, s_flsName, v_shouldBeFLS) {
ciMissing(ciNotFLStats, s_callingFunc, s_flsName, v_shouldBeFLS);
if(!df(v_shouldBeFLS.type) ||
v_shouldBeFLS.type != "FLStats") {
crsh("os.cinos1", ciNotFLStats, s_callingFunc + ": " + s_flsName + " is not of type 'FLStats'. Currently, [" + v_shouldBeFLS + "].");
}
}
//Intended for validate_form.js
function ciNotLoaded(s_callingFunc, vfb_cfg) {
var f = ciNotLoaded;
var sF = s_callingFunc;
var sDgnstcsStart = ".\n----------\nDiagnostics:\ns_jsDirUrl='" + sJSDIR + "' (as you provided to loadVF())\n";
if(df(vfb_cfg)) {
if(vfb_cfg.isVfpdOn() && !bLDD_VFPD) {
crsh("vf.gfem8", f, sF + "Permanent VF-Diagnostics are currently active, but '" + sJSDIR + "vf_perm_diagnostics.js'could not be loaded" + sDgnstcsStart + "bLDD_VFPD=" + bLDD_VFPD + "\nvfb_cfg.isVfpdOn()=" + vfb_cfg.isVfpdOn() + ", vfb_cfg.bDOnDflt=" + vfb_cfg.bDOnDflt + ", bVFPDInUrl=" + bVFPDInUrl + ", vfb_cfg.sFrmNm='" + vfb_cfg.sFrmNm + "'\nwindow.location.search='" + window.location.search + "'\nvfb_cfg.isVfpdOn()=" + vfb_cfg.isVfpdOn() + "'\nbLDD_VFPD=" + bLDD_VFPD);
} else if(vfb_cfg.isCIBCOn() && !bLDD_CIBC) {
crsh("vf.gfem9", f, sF + "vfb_cfg.isCIBCOn() equals true, but '" + sJSDIR + "vf_cib_config.js' or '" + sJSDIR + " could not be loaded" + sDgnstcsStart + "vfb_cfg.sFrmNm='" + vfb_cfg.sFrmNm + "'\nbLDD_CIBC=" + bLDD_CIBC);
} else if(vfb_cfg.iDDPS != -1 &&
!bLDD_DBG) {
crsh("vf.gfem10", f, sF + "vfb_cfg.iDDPS equals something other than -1 (" + vfb_cfg.iDDPS + "), but '" + sJSDIR + "vf_dbgVF.js' could not be loaded" + sDgnstcsStart + "vfb_cfg.sFrmNm='" + vfb_cfg.sFrmNm + "'");
}
}
if((bLDD_CIBC || bLDD_DBG) &&
!bLDD_OD) {
crsh("vf.gfem11", f, sF + "Either " + sJSDIR + "vf_cib_config.js (" + bLDD_CIBC + ") or " + sJSDIR + "vf_dbgVF.js (" + bLDD_DBG + ") were loaded, but the required sub-file '" + sJSDIR + "vf_obj_dgnstcs.js' could not be loaded" + sDgnstcsStart);
} else if(df(sSifCfgUrl) &&
(!bLDD_STASIF || !bLDD_SIF_CFG ||
(aCMPTBL_ATTRS.length == 13))) {
crsh("vf.gfem12", f, sF + "s_relUrl2ASIFmt ('" + sSifCfgUrl + "') has at least one of the following problems:\n - It could not be loaded. Verify the path.\n - It does not call stASIF().\n - It does not contain the required variable and value 'bLDD_SIF_CFG=true;'" + sDgnstcsStart + "bLDD_STASIF=" + bLDD_STASIF + "\naCPMTBL_ATTRS.length=" + aCMPTBL_ATTRS.length + "\nbLDD_SIF_CFG=" + bLDD_SIF_CFG);
}
}
/**
PUBLIC FUNCTION
Intended for util_array.js
. Crash if the provided array is bad.
A 'bad' array...
- ...is undefined
- ...is zero elements in length
- ...has an undefined element
PARAMETERS
s_callingFunc
: The function calling this, for potential error messages only.
s_arrayNm
: The name of a_rray, for potential error messages only.
a_rray
: The array to analyze.
SIGNATURE
cibRA(s_callingFunc, s_arrayNm, a_rray)
**/
function cibRA(s_callingFunc, s_arrayNm, a_rray) {
ciMissing(cibRA, s_callingFunc, s_arrayNm, a_rray);
if(!isRA(a_rray)) {
crsh("ua.ciba1", cibRA, s_callingFunc + ": " + s_arrayNm + " is not an array according to util_array.isRA(). " + s_arrayNm + "=[" + a_rray.toString() + "].");
}
if(a_rray.length < 1) {
crsh("ua.ciba2", cibRA, s_callingFunc + ": " + s_arrayNm + " is zero elements in length.");
}
for(var i = 0; i < a_rray.length; i++) {
if(!df(a_rray[i])) {
crsh("ua.ciba3", cibRA, s_callingFunc + ": " + s_arrayNm + "[" + i + "] is undefined. " + s_arrayNm + "=['" + a_rray.join("', '") + "']");
}
}
}
//Intended for si_fmt.js
function cibLnRng(si_min, si_max, s_minName, s_maxName, s_whenProvided) {
cibInt(s_minName, si_min);
cibInt(s_maxName, si_max);
if(!df(si_min)) {
//This is the alternate minimum bound. We also know the
//max alt bound is undefined.
return;
}
//Both rqd/alt bounds have been provided.
if(si_min.length != si_max.length) {
crsh("snf.cnstr1", cibLnRng, "cibLnRng: " + s_whenProvided + s_minName + " ('" + si_min + "') and " + s_maxName + " ('" + si_max + "') must be the same length.");
}
if(parseInt(si_min, 10) > parseInt(si_max, 10)) {
crsh("snf.cnstr1", cibLnRng, "cibLnRng: " + s_whenProvided + s_minName + " ('" + si_min + "') must be (numerically) less than or equal to " + s_maxName + " ('" + si_max + "').");
}
}
//Intended for si_fmt.js
function cibInt(s_boundName, si_frmtBound) {
if(df(si_frmtBound) && !isNum(si_frmtBound, "false") ||
si_frmtBound < 0) {
crsh("snf.cnstr4", cibInt, "cibLnRng: The value of " + s_boundName + " ('" + si_frmtBound + "') must be an *integer* greater than -1.");
}
}
/**********************************************************
**********************************************************
**********************************************************
E:\a_sandbox\validate_form_js\crash_if.js...END
**********************************************************
**********************************************************
**********************************************************/