Alert on erroneous field input?
Posted: Tue Sep 20, 2011 11:13 am
Hi,
In our application, we need an alert to pop up when a user enters a numeric value above a certain threshold in a given field. Ordinarily, I figured this would be handled with a Xataface validator, but we want the record to be save-able even if the offending value has been entered, which won't work with Xataface validators because with these one must first correct the errant value (to avoid matching the condition) in order to pass on to saving the record.
That is, in my delegate class, I tried to do handle this "warning" case by adding an additional condition:
But though I enter a value >= 109, no message appears; the appropriate message does appear when I change the return to false in my elseif condition, but then I can't save the record until the value is corrected.
Is there a way to do this in the validator or do I need a separate Javascript or Ajax-style warning to pop up when the user enters something beyond the threshold? If the latter is the best approach, I suppose I'd use a widget:att:onclick and then call my external javascript, but I'm uncertain of the syntax for that call, or for that matter, how I might call one of the available external Javascript validation libraries.
Any pointers would be most welcome. . .
Thanks!
In our application, we need an alert to pop up when a user enters a numeric value above a certain threshold in a given field. Ordinarily, I figured this would be handled with a Xataface validator, but we want the record to be save-able even if the offending value has been entered, which won't work with Xataface validators because with these one must first correct the errant value (to avoid matching the condition) in order to pass on to saving the record.
That is, in my delegate class, I tried to do handle this "warning" case by adding an additional condition:
- Code: Select all
function fieldname__validate(&$record, $value, &$params){
if ( $value < 0 || $value > 228 ){
$params['message'] = 'Sorry: must be between 0 and 228';
return false;
}
elseif ( $value >= 109 ) {
$params['message'] = 'Values greater than 108 are very unlikely.';
return true;
}
else
return true;
}
But though I enter a value >= 109, no message appears; the appropriate message does appear when I change the return to false in my elseif condition, but then I can't save the record until the value is corrected.
Is there a way to do this in the validator or do I need a separate Javascript or Ajax-style warning to pop up when the user enters something beyond the threshold? If the latter is the best approach, I suppose I'd use a widget:att:onclick and then call my external javascript, but I'm uncertain of the syntax for that call, or for that matter, how I might call one of the available external Javascript validation libraries.
Any pointers would be most welcome. . .
Thanks!