<<BACK HOME CNCPT TTRL JS | sf.net/projects/validateformjs | [ u | s | M | ? ] |
rqd dec eml int len mcr bss trm sif | All Concepts | |
frm txt pwd txa rdo sl1 chk slm | All Object Types |
validate_form.js
:' (
<< BACK
to main table of contents.
Contents:
...
Display error statistics...
Initialize error statistics...
Demonstrate utility.js
functions and capabilities...
SIFmt...
Test util_string.js
...
Basic validate_form.cibSprWSbRng()
developer errors...
Special validate_form.cibSprWSbRng()
tests: text.sMsgBadLength
and sanity checks...
Attribute compatibility....
General JavaScript sanity checks.validate_form.js
, the one who creates HTML forms, will see. Unless you've introduced the error yourself (not tested your code before launching), there are no errors on this page that your users will ever see, or could ever cause.[err stats] [reset]
Demonstrations of utility.js
functions and capabilities...
: Display error statistics in an alert box, for the just-occured error: sCrshCd
, sCrshMsg
and bCrshd
(all existing in utility.js
) and the expected error ID, if any. If this page was just loaded, or you just clicked the immediately-below initialize link, then this will display default (non-error) values. Note this dialog also displays the expected error, as defined and declared in this html document only. The expected error is not part of utility.crsh()
....
Initialize error statistics, as if you just loaded this web page....
Crash with neither an alert box nor message redisplay. Gives no response. Must look in the JavaScript Console....
Crash with an alert only....
Crash with a redisplay only. Must press your browser's 'back' button to return....
Crash with both an alert and redisplay. This is what happens in the reality. Must press your browser's 'back' button to return.These tests either "crsh", give an alert box (due to a fundamental error, beyond even a crash), or do nothing (when "successful" according to the function).
crsh
ciMissing
TOP
Test my sanity
Thanks to Laurent Vallis, I realize I fundametally erred in regards to the differences between null, undefined, zero, empty string, 'undefined', 'null', and [anything else which is defined]. Check out the source for runAllSanityTests()
to see how I've tried to verify the differences.
Zero, single and double quotes are all defined and equal to false but do not equal each other. Makes no sense, right? I thought so, too.
I distinguish between 'uncreated' and 'undefined'. 'Undefined' is simply not enough to describe all situations. To say that sMyVariable
is "uncreated", means that neither 'var sMyVariable;
' or 'var sMyVariable = 'whatever';
' exist in your code. To say that a variable is "undefined" means the variable has been created, but has not yet been assigned a value.
Take this entire html file, which crashes with 'Error: sMyVariable is not defined
':
<HTML><BODY>
View the source
<SCRIPT LANGUAGE="JavaScript1.3">
//<!---
alert("sMyVariable='" + sMyVariable + "'");
//--->
</SCRIPT>
</BODY></HTML>
However, when 'var sMyVariable...
' exists in your code, before or after (regardless if a value is defined), then you can reference sMyVariable
anywhere else, even before the 'var' line. Take the following HTML files, neither of which crash. They both successfully output "sMyVariable='undefined'
" in an alert box:
<HTML><BODY>
View the source
<SCRIPT LANGUAGE="JavaScript1.3">
//<!---
var sMyVariable;
alert("sMyVariable='" + sMyVariable + "'");
//--->
</SCRIPT>
</BODY></HTML>
<HTML><BODY>
View the source
<SCRIPT LANGUAGE="JavaScript1.3">
//<!---
alert("sMyVariable='" + sMyVariable + "'");
var sMyVariable;
//--->
</SCRIPT>
</BODY></HTML>
[err stats] [reset]
Demonstrations and tests of SIFmt
-attributes (sMsgTxt*)
Each validate_form.js
attribute has restrictions to which object types (form
, text
, ...) they may be associated; this is called Object Compatibility. Each attribute also has restrictions to which other attributes may be associated to that element at the same time; this is called Attribute Compatibility.
All 'x'-s, 'X'-s and 'c'-s are clickable, triggering a single unit test.
# | Attribute | Object Compatibility
Run every possible test |
Attribute Compatibility (#)
Run every possible test |
|||||||||||||||||||
![]() |
![]() |
![]() |
![]() |
![]() |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13.. |
||||
0 |
sMsgRequired |
X | c |
c |
c |
c |
n/a | c |
c |
c |
c |
c |
x |
c |
c |
c |
x |
c |
c |
c |
||
1 |
sMsgTxtDec |
X | c |
X | X | X | c |
n/a | X | X | c |
x |
x |
c |
c |
c |
x |
c |
c |
X | ||
2 |
sMsgTxtEmail |
X | c |
X | X | X | c |
X | n/a | X | c |
x |
x |
c |
c |
c |
x |
c |
c |
X | ||
3 |
sMsgTxtInt |
X | c |
X | X | X | c |
X | X | n/a | X | x |
x |
c |
c |
c |
x |
c |
c |
X | ||
4 |
sMsgBadLength |
X | c |
c |
X | X | c |
c |
c |
X | n/a | x |
x |
c |
c |
c |
x |
c |
c |
X | ||
5 |
sMsgMCRange |
X | X | X | X | c |
c |
x |
x |
x |
x |
n/a | x |
x |
x |
x |
x |
x |
x |
x |
||
6 |
asGlobalBadSubStrs |
c |
X | X | X | X | x |
x |
x |
x |
x |
x |
n/a | x |
x |
x |
c |
x |
x |
x |
||
7 |
bsNoBadSubStrs |
X | c |
c |
X | X | c |
c |
c |
c |
c |
x |
x |
n/a | X | X | x |
c |
c |
c |
||
8 |
asBadSubStrs |
X | c |
c |
X | X | c |
c |
c |
c |
c |
x |
x |
X | n/a | c |
x |
c |
c |
c |
||
9 |
sMsgBadSubStr |
X | c |
c |
X | X | c |
c |
c |
c |
c |
x |
x |
X | c |
n/a | x |
c |
c |
c |
||
10 |
bsGlobalTrimSpaces |
c |
X | X | X | X | x |
x |
x |
x |
x |
x |
c |
x |
x |
x |
n/a | x |
x |
x |
||
11 |
bsTrimSpaces |
X | c |
c |
X | X | c |
c |
c |
X | c |
x |
x |
c |
c |
c |
x |
n/a | X | X | ||
12 |
bsDontTrimSpaces |
X | c |
c |
X | X | c |
c |
c |
X | c |
x |
x |
c |
c |
c |
x |
X | n/a | X | ||
13.. |
sMsgTxt* |
X | c |
X | X | X | c |
X | X | X | X | x |
x |
c |
c |
c |
x |
X | X | n/a |
What | crsh() Code | Notes |
X | vf.ciai1 |
The attribute may not be associated to this object type. |
c | none | The attribute may be associated to this object type. |
What | crsh() Code | Notes |
x |
vf.ciai1 |
Exactly one of the attributes is associated to an object type that it should not be. |
X | vf.ciai2 |
Both attributes, individually, are object-compatible with the object's type, but it is illegal for both these attributes to be associated to it at the same time.. |
c |
none | The attributes are both object- and attribute-compatible. |
Notes:
validate_form.ciAttrIncmptbl()
directly, which is why there are no sub-attributes (such as iMCMin
for sMsgMCRange
) or super-attributes (such as form.asGlobalBadSubStrs
for text.bsNoBadSubStrs
) in the code snippets.bs
') are considered 'associated' only when equal to the string value of 'true'.asGlobalBadSubStrs
and sMsgBadSubStr
are incompatible; while it is possible for two elements to each have one of these attributes, no single element can ever have both these attributes associated to it at once.sMsgRequired
and sMsgMCRange
are indeed attribute-compatible, because they can both exist on the same 'checkbox' element. But sMsgMCRange
is not object compatible with 'text' elements, while sMsgRequired
is. Therefore, this compatibility only makes sense with regard to checkboxes. On any other element type, sMsgMCRange
would cause a crash with the following error (for example): "'sMsgMCRange' is an incompatible attribute with the object's type ('text')
".util_string.js
util_string.js
(run all tests):[err stats] [reset]
validate_form.cibSprWSbRng()
main developer errorsFor further information on the issues dealt with in this section, see the header documentation for validate_form.cibSprWSbRng()
, located at the bottom of the "PRIVATE FUNCTIONS
" section in that file.
Unit test everything in this table
DEVELOPER ERROR | Bound Provided? | Super attribute tested | ||||||
sMsgBadLength |
sMsgTxtInt |
sMsgTxtDec |
sMsgMCRange |
|||||
min | max | txt |
txa |
txt |
txt |
chk |
slm |
|
Bound exists, but super attribute does not | x | go |
go |
go |
go |
go |
go |
|
x | go |
go |
go |
go |
go |
go |
||
x | x | go |
go |
go |
go |
go |
go |
|
Super attribute exists (as it does for all the below tests in this table), but sub bounds don't. | go |
go |
n/a | n/a | go |
go |
||
Minimum bound is greater than maximum bound. | x | x | go |
go |
go |
go |
go |
go |
Bound is a string. | x | go |
go |
go |
go |
go |
go |
|
x | go |
go |
go |
go |
go |
go |
||
x | x | go |
go |
go |
go |
go |
go |
|
Bound is a decimal. | x | go |
go |
go |
n/a | go |
go |
|
x | go |
go |
go |
n/a | go |
go |
||
x | x | go |
go |
go |
n/a | go |
go |
|
Bound is zero (one too low). | x | n/a | n/a | n/a | n/a | go |
go |
|
x | n/a | n/a | n/a | n/a | go |
go |
||
x | x | n/a | n/a | n/a | n/a | go |
go |
|
Bound is negative one (two too low). | x | n/a | n/a | n/a | n/a | go |
go |
|
x | n/a | n/a | n/a | n/a | go |
go |
||
x | x | n/a | n/a | n/a | n/a | go |
go |
|
Bound is negative ten. | x | n/a | n/a | n/a | n/a | go |
go |
|
x | n/a | n/a | n/a | n/a | go |
go |
||
x | x | n/a | n/a | n/a | n/a | go |
go |
|
Bound is six (one too high). | x | n/a | n/a | n/a | n/a | go |
go |
|
x | n/a | n/a | n/a | n/a | go |
go |
||
x | x | n/a | n/a | n/a | n/a | go |
go |
|
Bound is fifty (way too high). | x | n/a | n/a | n/a | n/a | go |
go |
|
x | n/a | n/a | n/a | n/a | go |
go |
||
x | x | n/a | n/a | n/a | n/a | go |
go |
[err stats] [reset]
Special validate_form.cibSprWSbRng()
errors: text.sMsgBadLength
and sanity checksFor further information on the issues dealt with in this section, see the header documentation for validate_form.cibSprWSbRng()
, located at the bottom of the "PRIVATE FUNCTIONS
" section in that file.
Unit test everything in this section
text.sMsgBadLength
Note that text
and password
elements are special because they also can have the default HTML MAXLENGTH
attribute, in addition to iMaxLength
When both iMinLength
and MAXLENGTH
are provided, iMinLength
may not be greater than MAXLENGTH
.
The following list demonstrates sanity checks only, there is nothing here a developer should ever encounter:
bs_decOrInt
, bs_rangeRqdIfSprPrvd
, s_nameSprAttr
, s_nameMin
, s_nameMax
bs_decOrInt
invalid: string, 8, 0...
: Run all unit tests.validate_form.getFormErrorMsgs()
[
docs
]sMsgMCRange
[docs
]...
: Run all sMsgMCRange
related unit tests.checkbox
specific:
select-multiple
specific:
textarea
sMsgBadLength
...
:
Run all textarea.sMsgBadLength
related unit tests [
docs
].
sMsgBadLength
not provided, but the following bounds are provided: min
, max
, both
sMsgBadLength
is provided, but the bounds are bad: no bounds
, min > max
, min -10
, min -1
, max -10
, max -1
, min string, max string
, min dec
, max dec
, both dec
...
Test cibSprWSbRng()
- Test
cibSprWSbRng()
:
- Valid tests that should do nothing:
no super attr at all
, unrestricted min 1
, unrstr min 0
, unrstr max 1
, unrstr max 0
, minimally restr min 1
, maximally restr min 1
, both restr min 1
, min restr max 1
, max restr max 1
, both rstr max 1,
min restr both 1
, max restr both 1
, both rstr both 1
Demo forms for testing