Page 1 of 1

Response indicator for a button

Posted: Fri Oct 23, 2020 9:02 am
by Theju112
Dear Team,

My second question for the day.
I am attempting to understand the correct usage of the response property of button elements. The way I understood is that, if we bind the response property of a button to a variable whose data type is set to indicator, the bound variable value would get set to *ON, when the button is clicked.

But it seems this isn't the case. For example:
mapind.JPG
mapind.JPG (22.19 KiB) Viewed 3701 times
So, I was expecting that the value of MapUpdate would get set to *ON on clicking the button to which it is bound. But it doesn't work that way I guess.

So If I want to execute an action based on the button clicked on a rich display, how should I proceed?

Re: Response indicator for a button

Posted: Fri Oct 23, 2020 9:31 am
by Scott Klement
Yes, that is correct, the variable bound to the response property will be set to '1' (which can be referred to as *ON in RPG). Also, the screen is submitted back to the server when a button is clicked that has a response property set.

It is important that you only use the response property or the onclick event, never both.

Re: Response indicator for a button

Posted: Sat Oct 24, 2020 10:43 am
by Theju112
Hi Scott,

As you seem to have guessed correctly, I had used the onClick property in addition to the Response property.

Does the response indicator not work if onClick is set as well?

I needed to run some client side validations which I included in the onClick property. If that would not work, what approach can be followed in this scenario?

Re: Response indicator for a button

Posted: Sat Oct 24, 2020 7:04 pm
by Scott Klement
Add a second button and set its visibility to "hidden" so the user never sees it. Bind the reponse to this hidden button.

Remove the response from the first button. Have the onclick do whichever validations are needed, and then run pui.click() to click the 2nd button and submit the screen.

Or, alternately, remove the "onclick" and put the validations in the screen-level onsubmit event. (That will run the validations for all things that submit thee screen rather than just the one button, however.)

Re: Response indicator for a button

Posted: Sat Oct 24, 2020 10:18 pm
by Theju112
Scott Klement wrote:Add a second button and set its visibility to "hidden" so the user never sees it. Bind the reponse to this hidden button.

Remove the response from the first button. Have the onclick do whichever validations are needed, and then run pui.click() to click the 2nd button and submit the screen.

Or, alternately, remove the "onclick" and put the validations in the screen-level onsubmit event. (That will run the validations for all things that submit thee screen rather than just the one button, however.)
Great thanks for helping to learn more!

Re: Response indicator for a button

Posted: Wed Oct 28, 2020 8:19 am
by Theju112
Hi Scott,

I think I am missing something trying to implement the hidden button "trick" you told me.

So, as you mentioned I removed the response indicator from my first button and added a second hidden button.

Below is the onClick js of the first button:

Code: Select all

//**PAVT Get the MAP iframe reference
var iframe = document.getElementsByTagName("iframe")[0];

//**PAVT Get the marker Latitude and Longitude values
var mapLat = iframe.contentWindow.document.getElementById("latitude").innerHTML;
var mapLong = iframe.contentWindow.document.getElementById("longitude").innerHTML;

//**PAVT Assign the marker Lat and Long values to the Hidden Latitude/Longitude fields on screen
changeElementValue("MAPLATH",mapLat);
changeElementValue("MAPLONGH",mapLong);

//**PAVT Update indicator to indicate that user wants map marker address to be used

pui.click('mapUpdBtn');
pui.submit();
The response of the mapUpdBtn has been bound to an indicator variable by the name mapUpdate.

But even after I click on the first button and control goes to the RPG (from pui.submit()), when I do an eval of mapUpdate in debug mode, it is blanks.

I am not sure what is being missed. One thing I noticed is that in the DDS of the file, the mapUpdate is a hidden character field not an indicator as I expected. Do you suspect something?


For now, I have changed the code to this in the onClick JS of the original button:

Code: Select all

//**PAVT Get the MAP iframe reference
var iframe = document.getElementsByTagName("iframe")[0];

//**PAVT Get the marker Latitude and Longitude values
var mapLat = iframe.contentWindow.document.getElementById("latitude").innerHTML;
var mapLong = iframe.contentWindow.document.getElementById("longitude").innerHTML;

//**PAVT Assign the marker Lat and Long values to the Hidden Latitude/Longitude fields on screen
changeElementValue("MAPLATH",mapLat);
changeElementValue("MAPLONGH",mapLong);

//**PAVT Update indicator to indicate that user wants map marker address to be used
changeElementValue("MAPUPDATE","YES"); --> Hidden output field.
pui.click('btnSubmit');
The back end RPG now sees the value of MapUpdate as "YES" as required.

Re: Response indicator for a button

Posted: Wed Oct 28, 2020 9:03 am
by Scott Klement
Use pui.click() to click the 2nd button, not pui.submit()

Re: Response indicator for a button

Posted: Wed Oct 28, 2020 9:38 am
by Theju112
Thats what I have already used?

Please see the last but one line of the 1st code snippet.

Re: Response indicator for a button

Posted: Wed Oct 28, 2020 11:56 am
by Theju112
Hi Scott,

Thanks for helping. I get your point now.

I was confused because only now did I come to know that binding a response indicator to a button causes it to submit somehow when clicked?

Works now.

Re: Response indicator for a button

Posted: Thu Oct 29, 2020 4:46 pm
by Scott Klement
Yes, when you click a button that's bound to 'response', it submits the screen. (We use that word, "Response" in several places to indicate that something returns control back to the server.)