There are times when the fields on a single form are not enough to provide the full functionality you want available to your users. In these cases, you may need to display a dialog that prompts your users to enter some additional information.
Aras Innovator 11.0 supports several different ways of opening dialogs. Please note that not all of these methods are supported in every version of Aras Innovator 11.0. The supported versions for each of these methods will be noted where appropriate.
Opening a Form with a Dialog
One of the more common uses for dialogs is to open a custom form. In this example, we will be opening this simple form below in a number of different ways.
Modal dialogs will work in Internet Explorer and Firefox in Aras Innovator 11.0 SP7 and earlier.
Returning a Value from a Modal Dialog
Before we open the dialog, we need to specify the functionality of the buttons on our form. Specifically, we want some way to return the name that a user enters into the textbox when a user clicks the OK button.
The onClick Field Event of the OK button on this form can be seen below.
The Cancel button simply calls
window.close(); without setting a return value.
Opening a Modal Dialog
Now that we have a way to return the name, we can use the sample code below to open this form using a modal dialog.
To demonstrate the halting capabilities of modal dialogs, I have included an Alert after the dialog is opened that uses the name entered into the form.
At the time this blog was released, Popup Dialogs work in all versions of Aras Innovator 11.0 using any supported browser including Google Chrome.
Returning a Value from a Popup
The way in which we specify a return value for a popup is different than for a Modal Dialog. You can see this in the sample below.
Similarly, the Cancel button simply closes the window with
parent.args.dialog.close(); with no return value.
Opening a Popup
By passing in the 'DefaultPopup' option instead of 'DefaultModal' to the
modalDialogHelper, we can open a popup dialog instead.
Note that in this example, we are passing in an additional "callback" argument. This callback function will only execute after the dialog is closed and is necessary due to the non-halting nature of Popups.
To further demonstrate this non-halting behavior, I have included an alert after the call that opens the dialog. You will notice that this alert is called before the dialog is closed.
While this sample should function correctly in all currently released versions of Aras Innovator 11.0, the
modalDialogHelper API is being phased out. For newer versions of Aras Innvoator, we recommend using the most recent dialog API.
This new API streamlines both the way in which you open dialogs as well as the way in which you return values from them.
ArasModules.Dialog API works in Aras Innovator 11.0 SP7 and greater using any supported browsers.
Returning a Value from a Dialog
As you can see in this sample of returning a value from a dialog opened with this new API, the process of closing the dialog has been combined into a single function call.
The Cancel button will call
parent.dialogArguments.dialog.close(); with no arguments so that nothing is returned.
Opening a Dialog
The sample below will open a dialog using the
ArasModules.Dialog API. You can see that the arguments are roughly the same, though they have been streamlined for ease of use.
One thing you may have noticed in all of these samples is the use of the 'ShowFormAsADialog.html' page. This is a webpage included in the default installation of Aras Innovator that does as the name suggests and opens a dialog displaying the form corresponding to the ID passed in.
However, you can also replace the 'ShowFormAsADialog.html' with any other HTML page to display that instead.
Opening an HTML Page with a Dialog
For this example, I have written a simple HTML page that looks similar to our form.
I have named this "test_page.html" and have placed it into the /Client/customer/ folder of my code tree to separate it out from the standard installation of Aras Innovator 11.0 .
Now all we have to do is replace the content argument in our sample with this new HTML page.
In this example, I have also added a "header" parameter that I am using to set the header of the resulting dialog. You can add any number of custom parameters and retrieve them from your custom HTML page using the dialogArguments object.
For a downloadable example of opening a form from a dialog, please see the Custom Modal Dialog community project.
Please leave a comment if you learned something from this blog post or if you have any questions about any of the examples covered.