How to add Gravity forms gform_pre_render action in a plugin file - gravityforms

I am new to wordpress and this might be a really simple task.
I have a created a form using gravity forms plugin. I need to populate an options field in the form by making an API call. I had implemented this using gform_pre_render action and calling the function to make the API call. This code was in funtions.php of the active theme. This was working as expected.
However, now I'm required to do the same in a plugin file as I cannot have custom code in the themes file. When I place the same code in a plugin file and install the plugin, I am not getting the options field populated by API.
Is there any other way to do this? Please let me know. Any help is much appreciated.

You can use the gform_pre_render hook to add your custom code to the plugin. The only difference is that you need to use the add_filter function instead of add_action:
add_filter( 'gform_pre_render', 'populate_options' );
The add_filter function is the same as add_action except that it expects a callback function that returns a value. In the case of the gform_pre_render hook, the callback function should return the form object.
So, the code you want to run when the form is rendered should look something like this:
function populate_options( $form ) {
// your code goes here
return $form;
}

Related

Office web add-in : Office.initialize() function

I am struggling to understand, and don't find an example to exactly match what I am trying to achieve. Which is to have an MS Outlook ribbon bar icon, which when clicked displays a Dialogue Box. I played about with a demo, threw out superfluous functionality and got a Hello World going - but it is JQuery and I want to use to use AngularJs, to reuse much of an existing app.
Firstly, the example manifests all seem to have something like
<DesktopFormFactor>
<FunctionFile resid="functionFile" />
This seems to be for functions which are invoked when the user clicks an icon on the ribbon bar. Would I be correct to assume that I don't need that, if I just use a <script src=> tag to include an such files of functions?
My app will have only a single view, so whereas in the demo all *.js files have something like
// The Office initialize function must be run each time a new page is loaded
Office.initialize = function (reason) {
Would I be correct to assume that I need only have such call one, in the controller of my sole view?
Sorry if this seems pretty basic stuff, but all of the demos & docs seem to be close to what I want, but not exactly. Happy holidays!
Use of FunctionFile
FunctionFile specifies the source code file for operations that an add-in exposes through add-in commands(Ribbon buttons) that execute a JavaScript function instead of displaying UI.
Add-ins can decide either to display some UI in task pane or execute a javascript function in background. For UI-less add-ins, you will have to specify a FunctionFile.
In your case, FunctionFile can be ignored.
Use of Office.initialize
Office Add-ins include the Office.js library and the library expects your start-up code not to call any APIs until the library is fully loaded. There are two ways that your code can ensure that the library is loaded.
Use Office.initialize: An initialize event fires when the Office.js library is fully loaded and ready for user interaction. You can assign a handler to it.
Use Office.onReady: Office.onReady() is an asynchronous method that returns a Promise object while it checks to see if the Office.js library is fully loaded.
Examples:
Office.initialize = function () {
// Office is ready
};
Or
Office.onReady(function(info) {
if (info.host === Office.HostType.Outlook) {
// Based on host, decide what to display.
}
if (info.platform === Office.PlatformType.PC) {
// Make minor UI changes, if required.
}
});
In your case, you can use initialize/onReady once.

Using SELECT Options outside of Fields in Angular-Formly

I have found Angular-formly and it looks awesome. However, I have found a problem. We load the array of options for our <SELECTS> using an Ajax call so the select options can come asynchronously.
Unless I am missing something (hopefully) it seems we need to have the array when we create the "fields" for the form.
I have set up an example here http://jsbin.com/tihofegifu/edit
Ideally I would like to load the Array for the SELECT OPTIONs via ajax and formly to use the options like standard Angular does.
Another issue is editing the array using angular as in the button will not work.
What am I missing or doing Wrong?
I think the example you're looking for is on the website. Basically, you create a controller for the field to do the loading for you. You could also define that controller as part of a custom type.
Alternatively, you could also use expressionProperties which can accept a promise and you could do:
expressionProperties: {
'templateOptions.options': function() { /* return promise that resolves to the options you want*/ }
}
Good luck! Enjoy angular-formly :-)

Does view.postscript() allow you to call functions loaded as output scripts?

I am using <xpScriptBlock> to store the contents of two rather long client side functions that loads an ExtJS grid. I can call the function using clientside javascript just fine.
I discovered that I need to show a different grid based on a condition in the underlining document. To reference the backend I moved the code to serverside and then tried to call the grid using view.postScript. This does not work and is the basis of my question.
Is this approach even possible? I do not wish to put all the code into the event. The functions are quite long and better kept in a script block for readability and maintainability. The functions are definitely loaded in the client, as I can manually load them using the firebug console. Perhaps I am missing something simple so I wanted to ask before changing my approach.
var typePO = document1.getItemValueString("typePO");
if(typePO == "AFS"){
view.postScript("loadGridAFS();")
} else {
view.postScript("loadGridOther();")
}
This code is in the serverside onClientLoad event of a panel. I have tried adding the 'return' keyword and it makes no difference.
UPDATE: I can't even get simple alerts to work using view.postscript(). Does this method only work in certain types of events in SSJS???
After some experimenting using a simple alert I can say that view.postScript() does NOT work everywhere.
For a test, I put the same code in an six event of the xpage. Here is an example of the code I used: view.postScript("alert('onClientLoad');"); I just changed the message to match the event.
Here are the results:
onClientLoad = nothing
beforePageLoad = XSP error
afterPageLoad = WORKS!
afterRestoreView = nothing
beforeRenderResponse = WORKS!
afterRenderResponse = nothing
I haven't tried every available event out there, but the bottom line here is that you shouldn't count on view.postscript() to work everywhere. And if it does do nothing, try a simple alert first to see of the event supports view.postscript before questioning the client javascript code you are attempting to run.

dynamic binding in CoffeeKup

I am writing an app with node.js and coffee-script and coffeekup as template engine. I have a form where I'd like to enable or disable a button depending on whether there are values in some input fields. I am wondering whether there is a straightforward mechanism like in Sproutcore or Ember, where just a binding will do. How should I go about it?
No, there is no such binding out of the box. You have to either implement something like Ember, Knockout or Serenade.js, or roll it yourself. If it's just this one form, I would just have a small script (jQuery below):
function validateForm() {
// Check if form fields are valid, return true if valid, false if not.
}
// Update the disabled attribute on a button inside "formId" anytime an input field is changed.
$("#formId").on("change", "input", function(event) {
$("#formId button").attr("disabled", !validateForm());
});

How to implement standard functionalities using SuiteScript

I'd like to build suitescript implementing same functionalities with standard function.
For instance on item detail page (List/WebSite/Items) clicking view button of any non inventory item, you could find out Convert To Inventory button.
Thanks to inspect that browser support, it shows some as follows
I want to build script that archive same functionalities like getNLMultiButtonByName('multibutton_convertinvt').onMainButtonClick(this);return false; but it throws error like getNLMultiButtonByName is not defined.
I want your help.
Regard
Probably you're looking for something similar
function onLoad(type, form, request){
if(type=='view') {
form.addButton('custpage_button','Custom Button',"getNLMultiButtonByName('multibutton_convertinvt').onMainButtonClick(this);return false;");
}
}

Resources