Page 1 of 3

Using JS to Clear a Widget's Bound Value

Posted: Wed Feb 05, 2014 4:56 pm
by DaveLClarkI
I have a hidden text box which is intended to pass a message from the RPG program to the JavaScript in my page. After my JavaScript gets the message, I want to programmatically clear that value so that my JavaScript doesn't react to it, again, until the next time the RPG program sends another message.

I'm using the following code but this doesn't seem to be doing it because I'm getting "ghost" reactions to the last message sent.

Code: Select all

wob.displayMessageText = function(widgetId, msgSource, fadeDuration, position, event)
{
	var messageText = get(msgSource.id);	// get any message text
	changeElementValue(msgSource.id, "");	// clear any message text
	if (messageText <= " ") return;			// if no message text, then exit

...snip...

}
Is there something else that needs to be done when the value of a widget is bound to an RPG variable?

Re: Using JS to Clear a Widget's Bound Value

Posted: Fri Feb 07, 2014 5:32 pm
by David
Dave,

Was this one of the 3 items we talked about yesterday? Sorry, I've had quite a busy day today, I'll be following up on your other items, too.

Here it looks like you are doing it the right way, the changeElementValue() call will set the text box to empty string. There must be something else going on. Have you debugged the script to see exactly what happens? I ran a quick test and found no problems. Calling 'changeElementValue()' with empty string does properly clear the widget in all respects:

1. Visually cleared in the browser.

2. get() call after returns empty string.

3. Empty string submits to the server.

So, something else must be doing on or some other factor is in play. Is this one of those cases you mentioned where you have different widget types bound to same field or anything like that?

Re: Using JS to Clear a Widget's Bound Value

Posted: Fri Feb 07, 2014 5:50 pm
by DaveLClarkI
Yes, this is one of three three things I mentioned as outstanding issues in Thursday's meeting. But, no, this is not a case of multiple widgets trying to use the same bound field. After the script runs and before submitting back to the server, I did a Ctrl-F9 of the screen and I can still see the message text showing in the bound RPG field. Is that normal?

Re: Using JS to Clear a Widget's Bound Value

Posted: Fri Feb 07, 2014 5:56 pm
by David
Yes, it would be normal to see it still in the CTRL+F9 dump.

This is a capture of the last data that was received by the browser from the server. So it will have the data as at the time of screen render. It's not updated by the browser.

A good way to see what is submitted to the server if you want to check that is to use the browser's network request monitor. Try F12 tools in IE, Network tab.

You can see the POST request to program PUI0002110, which is the Genie server program.

Re: Using JS to Clear a Widget's Bound Value

Posted: Sun Feb 09, 2014 7:36 pm
by DaveLClarkI
I'm going to need some help, then, figuring out why I'm getting "ghost" reactions to the last message sent. Basically, even through the message is not being sent from the RPG program (confirmed by interactive debug on the RPG program), the get(msgSource.id) function in the JavaScript is returning the previous message text such that it displays on the screen again and again.

Re: Using JS to Clear a Widget's Bound Value

Posted: Mon Feb 10, 2014 1:05 am
by Scott Klement
As an aside, I find this code confusing, maybe someone can explain it to me?

Code: Select all

   if (messageText <= " ") return;         // if no message text, then exit
It's the <= " " part that baffles me. You are looking for strings that are less than blanks? Is an empty string less than a blank? Or more? How can you even quantify what an empty string will be?

I suspect that you know from prior experience than an empty string is less than a blank (why else would you code this) but to me it's quite puzzling. I would've found it much clearer if you trimmed the blanks from messageText and then compared against an empty string ("").

Am I right? OR, can you explain what that actually does when you set a string to "" and then compare it to <= " "?

Re: Using JS to Clear a Widget's Bound Value

Posted: Mon Feb 10, 2014 10:22 am
by David
It's hard to say what is going wrong here from the limited details.

Do you have a simple example that demonstrates the problem that we could try here?

Re: Using JS to Clear a Widget's Bound Value

Posted: Mon Feb 10, 2014 10:45 am
by DaveLClarkI
Simple? No, I'll have to send you my objects like I did for the tab panel issue. Working on it...

Re: Using JS to Clear a Widget's Bound Value

Posted: Mon Feb 10, 2014 6:20 pm
by David
Not sure if you received my email on this? I had sent you FTP account details where you could upload the example.

Re: Using JS to Clear a Widget's Bound Value

Posted: Tue Feb 11, 2014 10:42 am
by DaveLClarkI
Yes, uploaded last night and sent email with instructions.