Vermont Validation
From PikaDocs
Javascript data validation as used in Vermont
| Table of contents |
Introduction
I had originally planned to use LSNC's validation basically as is. However after running into a Firefox bug and a discussion with a programmer at Pika Software (see here (http://www.openpika.org/archives/2006/02/validation_quir.html) for more information) I'm trying a different approach. I am initially using only onSubmit() validation.
I've adapted the code from LSNC to fit this purpose. Basically it works as follows:
1) In the /js/validation.js file you can set several variables that mark the parameters of what is acceptable data. Right now this is really basic stuff.
2) In every subtemplate you want to validate, you add 2 things:
2A) A link to the validation file: at the top of each file add this:
<script type="text/javascript" src="/js/validation.js"></script>
and
2B) a call to the pk_validate() function in the onSubmit method of the form, which you add
You tell the pk_validate() function which fields should be required.
The function then looks through your form for any fields it knows how to validate (open_date, close_date, birth_date, ssn, email, etc.) and validates them.
The syntax of calling pk_validate() is
onSubmit="pk_validate(formname,'fieldtorequire1,fieldtorequire2');"
So right now I am differing from the LSNC approach in 2 ways:
1) I am not using any onChange() validation right now
2) There are some fields I am not going to bother validating that LSNC does. For instance, the opened_before field and similar fields on the case list search screen. If someone wants to search for cases opened before 1/1/1900 I don't care enough to stop them.
Files to modify:
- /subtemplates/alias.html
<script type="text/javascript" src="%%[base_url]%%/js/validation.js"></script> <form action="dataops.php" method="POST" name="forms1" onSubmit="return pk_validate(forms1,'')">
- /subtemplates/case_conflict.html - We modified this subtemplate to include a form. Other programs will not need to add validation to this file unless you customized it
- /subtemplates/case_contact_list.html - adding a new person to a case
<script type="text/javascript" src="%%[base_url]%%/js/validation.js"></script> <table id="middle-content" width="100%" summary=""> <tr valign="top"> <td class="side-column"> <h2>Contact Info.</h2> <form name="form1" method="get" action="%%[base_url]%%/case_contact.php" onSubmit="return pk_validate(form1,'')">
- /subtemplates/case_screen.html
At the top:
<script type="text/javascript" src="%%[base_url]%%/js/validation.js"></script>Around line 81: (this form didn't have a name so I added one)
<form action="%%[base_url]%%/case_contact.php" method="get" name="addperson" onSubmit="return pk_validate(addperson,'');">
- /subtemplates/contact_full.html - editing someone in the address book
<script type="text/javascript" src="%%[base_url]%%/js/validation.js"></script> <form action="%%[form_action]%%" name=fc method="post" onSubmit="return pk_validate(fc,'');">
- /subtemplates/contact_list.html - (where is this used? - Andrew)
<script type="text/javascript" src="%%[base_url]%%/js/validation.js"></script> <form name="form1" method="get" action="%%[base_url]%%/addressbook.php" onSubmit="return pk_validate(form1,'')">
- /subtemplates/contact_name.html - (where is this used? -Andrew)
<form action="%%[form_action]%%" method=POST name="con_name" onSubmit="return pk_validate(con_name,'')" autocomplete="off">
- /subtemplates/intake_aliases.html - this one has an SSN field but the form tag is not in the subtemplate so can't use this method. Need to raise this with Pika software
- /subtemplates/intake_contact_list.html - screening a new client
<script type="text/javascript" src="%%[base_url]%%/js/validation.js"></script> <form name="form1" method="get" action="%%[base_url]%%/intake2.php" onSubmit="return pk_validate(form1,'')">
- /subtemplates/case-info.html
- /subtemplates/matter-info.html This is a custom file for Vermont's Matters module. You won't have it unless/until you have that module
- Need to add all of the activity files - at your discretion, I won't spell them all out here.
Get the external JS code
Misc Notes
Special Case: How to call 2 functions from the onSubmit event (or any other event)
onSubmit="return pk_validate(ws,'')&&update_status()"
References:
- Project_Claire:_JavaScript_~_Form_Field_Validation
- Project_Claire:_JavaScript_~_External_Validation_File
- Javascript_Validation
--Andrew Cameron 11:55, 15 Feb 2006 (EST) --Updated 6 Mar 2006 to include %%[base_url]%% in the include URLs
