If you are curious, or just down right bored with long posts, then I have a running copy of the demo application here: http://apex.oracle.com/pls/apex/f?p=45420:3. The demo application can be downloaded here: http://apex.oracle.com/pls/apex/f?p=45410:DOWNLOAD. To keep the examples as clean as possible, I have created a new page with the Create-button, so you have both alternatives available.
The Quick Solution
And what is wrong with a quick solution? Personally I feel the we programmers (me definitely included) are very good at complicating things. The rest of this post is dedicated to a more generic approach, but in my original comment I suggested this:
- Create an anchor-tag (link) anywhere on the page
- Set href attribute to the URL of your edit form page, let primary key item values remain blank (but be sure to pass them)
- Set the id attribute to callModalDialog
This would work just like the edit links in my original example, but ready to insert a new employee. Like magic :-)
The Elaborate Solution
The explanation below is based on the original modal dialog page in my sample application. To follow the example and repeat the steps, you need to start off with a copy of page 2 in my sample application.
To follow the example, start by creating a region button with the following values (mostly just accept defaults):
Button name: CREATE
The button should take you to the create/edit page, but without the fancy modal dialog.
A Note for Later
Removing the Original onclick-Event
To create a Dynamic Action which fires when the page has finished loading, do the following:
Create a new Dynamic Action at the page level
Give it a sensible name ("On Page Load")
Choose Event Page Load
And why, oh, why store the link value in an element attribute definitely not meant to hold a link value!?! It will overwrite any existing title-values, and makes both setting and retrieving code hard to read. On the other hand, it will keep the value with it's element, and support more than one create button on any given page. There are more than one alternate way of doing this, but hey, feel free to bring suggestions :-)
Anyway, click Create and you are done.
If you run your page now, clicking the Create button will not do anything (the onclick event was removed, but not replaced).
That was the hard part!
Calling the Dialog
The edit dialog Dynamic Action is already in place, all that has to be done is to adapt the existing Dynamic Action to include the new create button.
Edit the Modal Dialog Dynamic Action
Include: button[value=Create] as the JQuery Selector expression (total expression will now be: a[id^=callModalDialog],button[value=Create])
Click Apply and you are done.
Is the same as detailed in my last post. I have updated the dialog page in the sample application to include Create and Delete buttons, but that is it.
Quick or Slow?
Quick sound promising! Simplicity rules! There are some draw-backs, of course. Like where to put the link to find it later (a Display Only item properly named perhaps?)? Like the need to style a link as a button? Like the need to place the link in a region template position? It all adds up.
The generic (more elaborate) approach will work with any create button (well, not with the anchor template). Drop the Dynamic Actions onto the page, and it will work. On the other hand, the generic approach involves more code, more code is harder to maintain and more prone to breaking. Generic code requires a delicate hand (ie takes time), and is generally harder to read than code created for a specific task. This is all in the eye of the beholder, but on more than one occasion I have had the pleasure of revisiting my own old code and though: I didn't need to do that... I digress, I know. Besides, that is too great a topic to just be delegated to a digression :-)
So, should you use the quick link (pun intended :-))? My answer (being a consultant) is a definitive: It depends!