error handling how to with invalid data

Hi there,

this is bugging me for month now. I am close to a suitable solution, but I am still suffering. My Scriptcase support ticket helped me to get close to a solution, but no solution yet. I am really frustrated with the SC error handling…

  • I have 4 date/time fields, all grouped and format dd-mm-yyyy hh:mm or mm-dd-yyyy hh:mm depends on aktive language
  • I am comparing dates with Ajax OnClick, displaying sc_error_message if one date is invalid compared to another
  • I use sc_set_focus with Ajax OnBlur so it will take user back to the date field which has invalid date
  • But…when a user enters a wrong format or a date that is not in calendar (e.g. 99-99-2011 99:99), Scriptcase throws it’s own “Invalid Data” sc_error_message and moves on to the next field

Now…how can I check if Date is valid when it comes to format and range??? Is there any way to perform the sc_set_focus OnBlur when Scriptcase throws an automatic sc_error_message with a specific field?


Also, when I use my calendar with date field, my Ajax Events are not fired at all. Therefore the whole error treatment does not perform and I would need another check with OnValidation, which I would like to avoid.

It’s such a basic thing and Scriptcase is a powerful tool, but there is no suitable solution for error treatment yet or I am just incapable of using SC.

I used to handle errors OnValidation before, showing all sc_error_messages in 1 box when I try to add or update data. But here also I have more then 1 issue. I can’t focus invalid fields and I can’t tag single fields as invalid. Also the error message is shown at top of page and there is no auto scrolling when I perform an update of data. Therefore user hits the Update button in a long form and can’t see the error box that is at top of a long form. The auto scrolling works with adding a new data set though.

Re: error handling how to with invalid data

You will have to do this yourself in Javascript function:

focus:
document.F1.field_name.focus();

onBlur for field:

Example for phone. You can modify for date.


function sc_phone_onblur()
{
var phoneRE = /^d{3}-d{3}-d{4}$/;
var phoneF1 = document.F1.phone;
var phoneNo = phoneF1.value;

if (phoneNo.length > 0) {
if (phoneNo.match(phoneRE)) {
phoneF1.style.background = '#ffffff';
return true;
} else {
alert("The phone number entered is invalid!");
phoneF1.style.background = '#ffc0ff';
return false;
}
} else {
phoneF1.style.background = '#ffffff';
return true;
}

} 

Regards,
Scott.

Re: error handling how to with invalid data

oh boy…I really appreciate your help, but this is really complicated for me. I just started to learn PHP because of Scriptcase and now I need a JavaScript checkdate function to validate my date/time field?

Why can’t I checkdate with Ajax OnBlur and PHP? I tried this, but Scriptcase does not handle the code right.

As I mentioned, Scriptcase is validating the date/time field (grouped and format dd-mm-yyyy hh:mm with calendar) on it’s own and throws sc_error_message below the field when the date is invalid (e.g. 99.99.9999 99:99 or 31.11.2011 11:11). Isn’t there any way to check if Scriptcase threw an error with field and then set_focus back to the field OnBlur? There must be some value or variable that is bein returned by scriptcase so field gets sc_error_message…I want to check on that…

if ($date1 > $date2){
sc_error_message...;
sc_set_focus('field')
}
elseif (field = error_true){
sc_set_focus('field')
}
else{
echo "Valid Date";
}