Page 1 of 2
Can I update a field w/JS and reference in RPG
Posted: Mon Nov 06, 2017 3:46 pm
by ppbedz
Does anyone know if I can update a bound program field with javascript and access the value in an rpg program. I am using the following to update a program field with the grid row updated by a user. The value (4) appears on the screen, but when the program references it, it is 0. This is the js code:
applyProperty("T_RowNum", "value", RowNum);
applyProperty("T_RowNum", "field type", "output field");
In the enclosed example, the user clicks the decline button, a function turns the button red and sets the program field to 4. The program sees the value as 0, instead of 4.
Re: Can I update a field w/JS and reference in RPG
Posted: Mon Nov 06, 2017 4:02 pm
by Scott Klement
Output fields are output-only, their data is never sent back to the host. If you want the data sent back, you'll need to change it to a textbox.
Also, you should never use applyProperty() for the value property. The value property is a special case that should be changed using the pui.set() API (or changeElementValue -- which is the same thing as pui.set)
Re: Can I update a field w/JS and reference in RPG
Posted: Mon Nov 06, 2017 4:33 pm
by ppbedz
Thank you Scott,
I changed my code as suggested and the value is being retained. However, I am noticing that when control returns to the program the colors on my buttons disappear. I have functions that turn the buttons green/red when they are clicked. I am going to enclose my functions along with screen shots. (Looks like my screen shots are in reverse order)
Patti
Re: Can I update a field w/JS and reference in RPG
Posted: Tue Nov 07, 2017 10:58 am
by Scott Klement
Whenever you send control back to the RPG program and it does a new EXFMT, the entire display is re-drawn.
So if you're running custom JavaScript that changes the display, you'll need to re-run that code and re-do your changes after an EXFMT.
Re: Can I update a field w/JS and reference in RPG
Posted: Tue Nov 07, 2017 11:27 am
by ppbedz
got it... thank you!!!
Re: Can I update a field w/JS and reference in RPG-?
Posted: Wed Nov 08, 2017 4:15 pm
by ppbedz
Scott,
Regarding my buttons in the grid, once I click the button and the JS turns it the appropriate color, if I click again (without returning to the program), it does not go back into the function. I assume because it thinks the onclick has already been processed. Is there a way to turn off/reset the onclick at the end of my function so that if the user clicks it again, it will perform the function again? My scenario would be the user accidentally clicks the wrong button and clicks it again to "de-select" it. I tried the following, but it did not work.
getObj("B_Accept" + "." + row).clicked = false;
Thank you,
Patti
Re: Can I update a field w/JS and reference in RPG
Posted: Wed Nov 08, 2017 4:29 pm
by Scott Klement
Patti, the onclick event runs every time you click. It does not have any concept of "already processed" or anything like that, it just always runs the code when you click it.
Re: Can I update a field w/JS and reference in RPG
Posted: Wed Nov 08, 2017 4:34 pm
by ppbedz
Scott, That's interesting because I have an alert at the beginning of the function and it does not display when I click it again. That is what made me think the function was not being executed on the second click.
function clkAccBtn(row) {
var BtnAccColor = getObj("B_Accept" + "." + row).style.backgroundColor;
var AccColor = "#32CD32";
var DecColor = "#FF0000";
var DefColor = "transparent";
var AccBtn;
var DecBtn;
var AccChk = "0";
var DecChk = "0";
var RowNum = 0;
alert("accept button is " + BtnAccColor);
// Set the accept/decline buttons and corresponding check box
if (BtnAccColor == DefColor)
{
AccBtn = AccColor;
AccChk = "1";
DecBtn = DefColor;
}
else
{
AccBtn = DefColor;
}
getObj("OOgrid").grid.setDataValue(row, "S1ACCEPTED", AccChk);
getObj("OOgrid").grid.setDataValue(row, "S1DECLINED", DecChk);
applyProperty("B_Accept" + "." + row, "background color", AccBtn) ;
applyProperty("B_Accept" + "." + row, "field type", "button");
applyProperty("B_Decline" + "." + row, "background color", DecBtn) ;
applyProperty("B_Decline" + "." + row, "field type", "button");
pui.set("T_RowNum", RowNum);
getObj("B_Accept" + "." + row).clicked = false;
}
Re: Can I update a field w/JS and reference in RPG
Posted: Wed Nov 08, 2017 4:36 pm
by ppbedz
Scott,
The function is only executed again if I return control to the rpg program first.
Re: Can I update a field w/JS and reference in RPG
Posted: Wed Nov 08, 2017 4:51 pm
by Scott Klement
The only time I've run into stuff like that is if some JavaScript code gets stuck in a loop (or similar.) Since there's already JS code running and it hasn't finished (because it's stuck) subsequent code does not run.