Dec 12th, 2009, 9:08 PM
Hey Alexis,
Thanks for the reminder about this post.
So! Here's some very general pointers on how to do this for the JS RSV script. Since the built-in date validation code is pretty basic, we're going to bypass it altogether and write a custom function to do the validation for us. First, add a new rule to your rule list: this will call your custom function.
Next, as you described in your post, the check_date() function needs to do a couple of things. I wasn't completely sure about the rules you need to check for, but here's an example of how it would look:
That's the gist of it... the validation logic will be the next bit to sort out. Basically you'd need to extract & compare the various dates and do the math on them.
Sorry I'm being so general, but hopefully this gives you some idea of how to proceed - at least how to plug it into the main validation control flow.
- Ben
Thanks for the reminder about this post.
So! Here's some very general pointers on how to do this for the JS RSV script. Since the built-in date validation code is pretty basic, we're going to bypass it altogether and write a custom function to do the validation for us. First, add a new rule to your rule list: this will call your custom function.
Code:
rules.push("function,check_date");
Next, as you described in your post, the check_date() function needs to do a couple of things. I wasn't completely sure about the rules you need to check for, but here's an example of how it would look:
Code:
function check_date() {
// this bit would be generated server-side. This example assumes you're using PHP and the
// date is in yyyy-mm-dd format.
var study_date_start = "<?=$study_date_start?>";
// 1. find the form fields that contain the dates.
// 2. do whatever tests you want. You'd no doubt compare it with the value in study_date_start
// 3. if there are errors, return a variable like this - where problem_field is a reference to
// the form field that has a problem (e.g. document.getElementById("field1") )
// return [[problem_field, "your error message"]];
// if there are no error messages, return true:
return true;
}
That's the gist of it... the validation logic will be the next bit to sort out. Basically you'd need to extract & compare the various dates and do the math on them.
Sorry I'm being so general, but hopefully this gives you some idea of how to proceed - at least how to plug it into the main validation control flow.
- Ben