PaulNieuwelaar / alertjs

Dialog Builder allows you to create fully customisable dialogs and popups in Dynamics 365.
https://www.magnetismsolutions.com/our-products/alertjs-alert-popup-for-d365
Other
96 stars 38 forks source link

Pass value to Callback function from HTML #17

Closed sameer678 closed 6 years ago

sameer678 commented 6 years ago

I am using below method to open HTML Web resource. Is there any way to return value to callback method from HTML?

var alertButton = new Alert.Button(); alertButton.label = "Close"; alertButton.callback = CallbackFunction; var array = new Array(); array.push(alertButton); Alert.showWebResource(url, 800, 500, "", array, null, true, 10);

PaulNieuwelaar commented 6 years ago

Hi, in your callback function you can make a call to Alert.getIFrameWindow() which returns the window object of your webresource. You can then access inputs etc from the webresource.

E.g.:

function CallbackFunction() {
    var iFrameWindow = Alert.getIFrameWindow();
    var value = iFrameWindow.document.getElementById("somefield").value;
}

Also note you can simplify your code a lot:

Alert.showWebResource(url, 800, 500, "", [new Alert.Button("Close", CallbackFunction)], null, true, 10);

Kind Regards, Paul

sameer678 commented 6 years ago

Thanks Paul for the quick response. I can access Web resource DOM elements. Is there any way we access HTML Web resource variables or methods? I want to return array from HTML to call back?

PaulNieuwelaar commented 6 years ago

Sure, just set a global variable inside your web resource then access it using the get IFrame window method.