There are some notable additions to PeopleCode support for Fluid UI in terms of the built-in functions and properties that are delivered.
In Classic, if we had a requirement to invoke a JavaScript function from PeopleCode, then one option would be to use a HTMLAREA on the page and dynamically populate the HTMLAREA value with the JavaScript code.
In Fluid, we can very easily use the AddOnLoadScript function to invoke JavaScript in the onload event and the Field Class - JavaScriptEvents property to associate JavaScript events to a Field.
For the purposes of a demonstration, I created a simple Fluid page with 3 button fields.
I added the following Page Activate PeopleCode:
Declare Function SetViewport PeopleCode PTLAYOUT.FUNCLIB FieldFormula;
/* Set ViewPort Meta for SFF Scaling */
SetViewport(""); /* apply the system default viewport setting */
AddStyleSheet(StyleSheet.PSBASE_LAYOUT);
AddJavaScript(HTML.CSK_PC2JS_FLU);
AddOnLoadScript("pageActivate();");
CSK_FL_PC2JS_WK.BUTTON1.JavaScriptEvents = "onclick='javascript:button1();'";
CSK_FL_PC2JS_WK.BUTTON2.JavaScriptEvents = "onclick='javascript:button2();'";
CSK_FL_PC2JS_WK.BUTTON3.JavaScriptEvents = "onclick='javascript:button3();'";
Here is the JavaScript in the HTML Object CSK_PC2JS_FLU:
var pageActivate = function() {
console.log('JS invoked from Page Activate');
};
var button1 = function() {
console.log('JS invoked by Button 1 OnClick');
};
var button2 = function() {
console.log('JS invoked by Button 2 OnClick');
};
var button3 = function() {
console.log('JS invoked by Button 3 OnClick');
};
Click here to check out a demo video >>>> SWF File
In Classic, if we had a requirement to invoke a JavaScript function from PeopleCode, then one option would be to use a HTMLAREA on the page and dynamically populate the HTMLAREA value with the JavaScript code.
In Fluid, we can very easily use the AddOnLoadScript function to invoke JavaScript in the onload event and the Field Class - JavaScriptEvents property to associate JavaScript events to a Field.
For the purposes of a demonstration, I created a simple Fluid page with 3 button fields.
I added the following Page Activate PeopleCode:
Declare Function SetViewport PeopleCode PTLAYOUT.FUNCLIB FieldFormula;
/* Set ViewPort Meta for SFF Scaling */
SetViewport(""); /* apply the system default viewport setting */
AddStyleSheet(StyleSheet.PSBASE_LAYOUT);
AddJavaScript(HTML.CSK_PC2JS_FLU);
AddOnLoadScript("pageActivate();");
CSK_FL_PC2JS_WK.BUTTON1.JavaScriptEvents = "onclick='javascript:button1();'";
CSK_FL_PC2JS_WK.BUTTON2.JavaScriptEvents = "onclick='javascript:button2();'";
CSK_FL_PC2JS_WK.BUTTON3.JavaScriptEvents = "onclick='javascript:button3();'";
Here is the JavaScript in the HTML Object CSK_PC2JS_FLU:
var pageActivate = function() {
console.log('JS invoked from Page Activate');
};
var button1 = function() {
console.log('JS invoked by Button 1 OnClick');
};
var button2 = function() {
console.log('JS invoked by Button 2 OnClick');
};
var button3 = function() {
console.log('JS invoked by Button 3 OnClick');
};
Click here to check out a demo video >>>> SWF File
Hei
ReplyDeleteHow Can I execute fieldchange event of a field in the page using javascript?
You should try to avoid such things unless absolutely required. I am not sure what your requirement is but I would not recommend this in Fluid.
DeleteHaving said that, you could follow a similar approach that we use in Classic:
https://pe0ples0ft.blogspot.com/2015/07/invoke-peoplecode-event-from-javascript.html
Technically, this should work in Fluid also.
I am just curious to know whether it is possible to achive it using Field Class - JavaScriptEvents property
DeleteHow would someone go about executing the window onload, focusin and focusout events in peoplecode?
ReplyDeleteYou can use the AddOnLoadScript delivered function for the window onload portion.
DeleteI would assume the javascriptevents at the field property level could handle the focusin and focusout events but I have not tried it myself.
Does that not work for you?
Hello Sasank!
ReplyDeleteThanks for all your posts . i am looking for one help , actually when i am calling message box function within prebuild event which call to again person selector component to select employee , i have written some validation with message box displaying to proceed or not , the problem is when i message box display all fluid page gets disturbed, and to overcome this i have re-directed url and refreshed but that is not the solution , is this possible to create one similar function for validation ? if yes can you give some pointers that will be great help.
Hello Sasank !!
ReplyDeletehope all good with you. i am looking for an option to view existing javascript used in peoplesoft ,for example it displayMoreAction() in expense module.
Try searching in App Designer using the "Find In" Option (Edit > Find In). Search the HTML objects in the entire database.
DeleteIf it is a javascript function, you should find it in the results.
Hi Sasank,
ReplyDeleteI have a requirement to disable copy & auto fill in password field when using RevalidatePassword().Its called on a classic page.
I tried various methods to disable copy/auto fill on that component, but nothing is working. Its not able to identify the password field.
Please help of you can think of any possible solution.
Thanks in advance.
Regards,
Fenil
Hello Sasank, Can, we pass variables to the on-click from peoplecode into the javascript function? Thanks, Cory Flowers
ReplyDelete