Focal Point
[SOVED] Maintain onBlur event handler acting strange

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/5441027582

May 28, 2008, 02:25 PM
brjohnson
[SOVED] Maintain onBlur event handler acting strange
Hi everyone,

I have run into a problem that has me scratching my head. I have a maintain project that has two tables...one for person info and another for order info. My goal is to add an event handler(either onChange or onBlur) that executes when someone enters a PersonID on an AddOrderForm. The code should check the Person table to see if that PersonId exists, and if it does exist display the persons name on the screen. If it doesn't a JS confirm box should pop-up asking the user if they would like to add a new Person record. The code that checks to see if the person exists follows
 STACK CLEAR GetPersonStack;
REPOSITION fow_clients.FOW_CLIENTS.PERSONID;
NEXT fow_clients.FOW_CLIENTS.PERSONID INTO GetPersonStack WHERE fow_clients.FOW_CLIENTS.PERSONID EQ AddOrderStack(1).PERSONID;
COMPUTE exist=GetPersonStack.FocCount; 

I bound the variable 'exist' to a hidden field on the form where the JS function can look. If the value is 1 then display the name...if it is 0 then display confirm box asking to enter new Person record. The problem is that the JS function fires off before Maintain can set the value in the hidden field, so JS always sees 0 in the field even if there is a Person record corresponding to the PersonID. I have tried making the event handler JS, and having it call the above Maintain code...then use a setTimeout command to give Maintain a chance to populate the 'exist' editBox, but this doesn't seem to work either. When I test the app I can see that the field is being populated with a 1 only after the event handler has completed. The Person table only has a few hundred records so it doesn't take long for Maintain to find the record, but that field only populates when the event handler is over.

If anyone has any suggestions or alternate ideas on how to achieve this functionality I am all ears.


P.S. on a related note why does the focus always return to the PersonID field when I run this event handler? Even when I explicitly set the focus to another field the focus returns to PersonID after having tabbed off the field and launching the event handler. When the event handler is onChange this isn't a major issue because if you hit tab again you move to the next field, but when it is onBlur you just get stuck tabbing and then returning over and over again.


Thanks

This message has been edited. Last edited by: brjohnson,


Bryan Johnson
WebFOCUS 7.7.03
Maintain
Win 7
Excel, PDF, HTML
May 29, 2008, 02:46 AM
GamP
Bryan,

Am I right in assuming that you bound the js function that checks the hidden field to the onchange event?
If so, then what happens is making sense.
Consider the timing in this. When something changes in the id field, then the js gets activated. This one does two things - call a maintain case, and checks the field.
But, these two things are mutually exclusive, because the first takes place on the server (requiring the js to exit) and the other one locally (requiring the js not to exit).
Split the js functions.
One to act upon the change of the field and call the maintain case.
This will return control to the server and result in a new page, with all data filled in.
This function needs to be bound to the id-field.
Then have a second js function that will act upon the value of the hidden field. This piece of js has to be bound to the form itself (done by dragging the js from the project explorer onto an empty space on the open form). This latter js will get executed after the page has been loaded.

Hope this helps ...


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
May 29, 2008, 10:42 AM
Maintain Wizard
There are actually 2 ways that I would do this.

The first is just with Maintain and not JavaScript. I would place a button or a text message on the form and make it Visible No. Then, if the person is not found, I would use:
WINFORM SET form.object.visible to YES

This displays the message and you can trigger what ever you want. Make it Visible NO when you are done.

The second is a JavaScript solution, but uses the OnLoad.JS funtion. This is attached to the form, and is run EVERY time the form is refreshed. So, you could have:

var OriginalOnload = document.body.onload;
document.body.onload = LoadFunct;

function LoadFunct() {
if (OriginalOnload) OriginalOnload ();
if (document.Display.X_Edit.value.length != 0)
{
var msgtext = Display.X_Edit.value;
alert(msgtext);
Display.X_Edit.value = '';
}
}

This routine checks a field on the form, and if it has a value, pop up a message. You could have it kick off another JavaScript routine or whatever else you need. Just remember to clear out the checked field when done, or the message will be displayed everytime.

Mark
June 02, 2008, 12:10 PM
brjohnson
Thanks very much both of you,

I was able to get it working...I chose to use the Maintain only strategy for checking for the user. I used the JS onLoad function to set the focus to the field after ID, if the ID field contains data, to prevent an endless tabbing loop. Just one thing still kinda bugs me(and its not a real big deal) the data in the ID field remains highlighted even though the focus is set on the next field. Like I said its not a big problem, but I was just curious if anyone knew why this was happening.

Thanks again for the help


Bryan Johnson
WebFOCUS 7.7.03
Maintain
Win 7
Excel, PDF, HTML
June 02, 2008, 03:33 PM
Dave Ayers
quote:
Just one thing still kinda bugs me(and its not a real big deal) the data in the ID field remains highlighted even though the focus is set on the next field.


Set the .select method as well as the .focus, and that should take care of it.


Regards,
Dave

http://www.daveayers.com

WebFocus/Maintain 7.6.4-8
on Win2000 and 2003 Server
June 02, 2008, 04:12 PM
brjohnson
That did take care of it...also while searching the forum I found this snippet of code from Mark that will set focus completely with Maintain.
 WINFORM SET FormName.FieldName.Focus to HERE; 
This works just fine...no javascript needed.


Bryan Johnson
WebFOCUS 7.7.03
Maintain
Win 7
Excel, PDF, HTML