Alert on erroneous field input?

A place for users and developers of the Xataface to discuss and receive support.

Alert on erroneous field input?

Postby lhat » 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:

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!
lhat
 
Posts: 40
Joined: Thu Aug 06, 2009 3:31 pm

Re: Alert on erroneous field input?

Postby shannah » Tue Sep 20, 2011 3:35 pm

Yes. If this is a soft validation (i.e. it shouldn't stop the user from saving) I'd just do it in javascript.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Alert on erroneous field input?

Postby lhat » Wed Sep 21, 2011 12:01 pm

Thanks, Steve--

But when I add to my fields.ini the line widget:atts:onclick = "doEntryWarn();" under the appropriate field and in that same directory I have my EntryWarn.js, nought happens when I click in the field--what am I missing? Should I use onchange, or is my field value test not working?

My EntryWarn.js says just this:

Code: Select all
<script type="text/javascript">
<!--
function threshold ( )
{
    if ( document.tablename.fieldname.value >= "109" )
    {
        alert ( "Woot!  Values of 109 and above are very unlikely!" );
    }
}
//-->
</script>


Any help most appreciated!
lhat
 
Posts: 40
Joined: Thu Aug 06, 2009 3:31 pm

Re: Alert on erroneous field input?

Postby shannah » Wed Sep 21, 2011 12:40 pm

Your validation function here is called threshold() but you are calling doEntryWarn() on the trigger.... perhaps I'm missing something?
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Alert on erroneous field input?

Postby lhat » Wed Sep 21, 2011 12:55 pm

I wondered if that might cause woe, but when I eliminated that function from the .js file, still no grease. I had thought that in order to call this function from the external EntryWarn.js I needed to stipulate the latter filename; are you saying I could put this javascript function right into my Delegate Class directly? (i.e., javascript in a php file?). Sorry to be dumb, but I am learning under your patient tutelage... :wink:
lhat
 
Posts: 40
Joined: Thu Aug 06, 2009 3:31 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 23 guests

Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved