SharePoint: Extending the DVWP – Part 6: Examining the Form Action Links
Author: Jim Bob Howard
As we saw in the last Extending the DVWP article, it’s possible to intercept the built-in process of the OK button on a SharePoint form. And we can extend that to the DVWP by adding to the JavaScript call within the HREF parameter of our form action links. But, there’s more we can do…
We can build and call workflows, too.
Examining the Links
Before we dig too deep, let’s focus on what is going on so we know what we’re changing.
Let’s take a quick look at what each of these links is doing, OOTB (out-of-the-box). For each of these, the code is fired from a JavaScript call using the HREF (hypertext reference) attribute of the A (anchor) tag.
Note: The line numbers below are relative to my document, so they won’t necessarily show up at the same point in yours. To find them in your page, in the Design pane, click on the link in question. This will bring the HTML block into view in the Code pane. For the Edit and Insert Templates, you’ll need to switch to those views in SPD to see the links. For more details, see the previous article in this series: Extending the DVWP – Rearranging Columns – Default and Edit Templates.
Edit
<a href="javascript: {ddwrt:GenFireServerEvent(concat('__cancel;dvt_1_form_editkey={',$KeyValue,'}'))}">edit</a>
The edit link is used to redraw the form with the Edit Template in place. It performs two functions:
- cancel (which causes the form to be redrawn); but also
- dvt_1_form_editkey is passed the ID of the current list item so that the Edit Template will be drawn for that record
Edit Template
As we’ve already seen, the edit link causes the page to be redrawn with an Edit Template (or form) for the current record, with two more links: save and cancel.
- save
- cancel
<a href="javascript: {ddwrt:GenFireServerEvent('__commit')}">save</a>
This call is very simple. It takes the content on the form that we have updated and commits it to the database. No questions, no other steps, just save my changes.
<a href="javascript: {ddwrt:GenFireServerEvent('__cancel')}">cancel</a>
Likewise, this is a simple call: cancel without saving. No confirmation, just quit it and redisplay the page as it was.
Insert
<a href="javascript: {ddwrt:GenFireServerEvent('__cancel;dvt_1_form_insertmode={1}')}">insert</a>
The insert link is used to redraw the form with the Insert Template in place. It, too, performs two functions:
- cancel (which causes the form to be redrawn); but also
- dvt_1_form_insertmode is passed a 1 (for ‘true’) so that the Insert Template will be drawn to create a new record
Insert Template
Again, like edit, insert causes a redraw of the screen with a "new" form laid out like the DVWP, with similar links:
- save
- cancel
<a href="javascript: {ddwrt:GenFireServerEvent('__commit')}">save</a>
This one is exactly like the save on the Edit Template, above. It commits the changes made.
<a href="javascript: {ddwrt:GenFireServerEvent('__cancel')}">cancel</a>
And this one cancels the insert and redraws the page as it was.
Delete
<a href="javascript: {ddwrt:GenFireServerEvent(concat('__cancel;__delete={',$KeyField,'=',$KeyValue,'};__commit'))}">delete</a>
The delete link redraws the DVWP with the Default Template, but without the deleted list item. It actually performs three functions:
- cancel (which keeps the form from doing its normal submit function);
- delete (which passes this item’s ID to the delete function); and
- commit (which commits the deletion to take place).
Notice that there is no verification that it should be deleted; it’s just gone (of course, we could easily recover it from the Recycle Bin). In a future article, we’ll change the way that works.
Next time: Changing the functionality of these links (with workflows, jQuery, the PreSaveAction() function, creating new Edit, and a combination of those) will be the focus of the next few Extending the DVWP articles.
Author: Jim Bob Howard
Jim Bob Howard is a web designer / webmaster in the healthcare industry. He has been working with SharePoint since March 2009 and enjoys sharing what he has learned. He is a moderator and frequent contributor to Stump the Panel, and answers SharePoint questions on Twitter (@jbhoward) and via email ([email protected]).
- SharePoint: Extending the DVWP - Part 1: Layout Enhancement - Rearranging Columns - Default and Edit Templates
- SharePoint: Extending the DVWP - Part 2: Layout Enhancement - Rearranging Columns - Insert Template
- SharePoint: Extending the DVWP – Part 3: Getting it All on One Line - DVWP Function Action Links
- SharePoint: Extending the DVWP – Part 4: Turning DVWP Action Links into Buttons
- SharePoint: Extending the DVWP – Part 5: Doing Stuff Before Save on Submit - PreSaveAction()
- SharePoint: Extending the DVWP – Part 6: Examining the Form Action Links
- SharePoint: Extending the DVWP – Part 7: Creating a Form Action Workflow
- SharePoint: Extending the DVWP – Part 8: Creating a Form Action Workflow - The After Math
- SharePoint: Extending the DVWP – Part 9: Oops! Failed Setting Processor Stylesheet
- SharePoint: Extending the DVWP – Part 10: Passing Workflow Variables to a Form Action Workflow
- SharePoint: Extending the DVWP – Part 11: Getting More Form Fields to the Workflow
- SharePoint: Extending the DVWP – Part 12: Adding More Form Fields from the Data
- SharePoint: Extending the DVWP – Part 13: Putting PreSaveAction() to Work – Creating Variables
- SharePoint: Extending the DVWP – Part 14: Putting PreSaveAction() to Work with jQuery
- SharePoint: Extending the DVWP – Part 15: User-Managed Dropdowns with Site Columns
- SharePoint: Extending the DVWP – Part 16: User-Managed Dropdowns - Loading Data
- SharePoint: Extending the DVWP – Part 17: User-Managed Dropdowns – Creating a Relationship list
- SharePoint: Extending the DVWP – Part 18: User-Managed Dropdowns – Loading the Relationship list – Part 1
- SharePoint: Extending the DVWP – Part 19: User-Managed Dropdowns – Loading the Relationship list – Part 2
- SharePoint: Extending the DVWP – Part 20: Cascading Dropdowns - Applying the jQuery
- SharePoint: Extending the DVWP – Part 21: Cascading Dropdowns - Three-tier Cascade
- SharePoint: Extending the DVWP – Part 22: Creating Title Based on Other Fields with jQuery
- SharePoint: Extending the DVWP – Part 23: Creating Title Based on Other Fields with a Workflow
- SharePoint: Extending the DVWP – Part 24: A Note to Readers
- SharePoint: Extending the DVWP – Part 25: Using an Audit Trail by Creating List Items with SPServices
- SharePoint: Extending the DVWP – Part 26: Modifying the Edit Template
- SharePoint: Extending the DVWP – Part 27: Adding an Alternate Edit Template to a DVWP
- SharePoint: Extending the DVWP – Part 28: Massage the Remove Template
- SharePoint: Extending the DVWP – Part 29: Modifying Form Action Workflows on the remove Template
- SharePoint: Extending the DVWP – Part 30: Using EasyTabs with Filtered DVWPs to Make Data Manageable
- SharePoint: Extending the DVWP – Part 31: Filling in Default Data on the insert Template with jQuery
- SharePoint: Extending the DVWP – Part 32: Filling in Default Data on the insert Template with Multiple DVWPs
- SharePoint: Extending the DVWP – Part 33: Modifying Total and Subtotal Row Layouts in DVWP
- SharePoint: Extending the DVWP – Part 34: Using Icons for Form Action Links
- SharePoint: Extending the DVWP – Part 35: Putting it All Together
- SharePoint: Extending the DVWP – Bonus: Fixing the Insert Form Action When "No Matching Items"
- SharePoint: Extending the DVWP – Bonus: Creating a Title Based on Dropdowns with jQuery
Hi Jim Bob
Using the DVWP, is it possible to create links between two web parts that are on different sites?
Iain
Probably, Iain. But, tell me a bit more about what sort of “link” you’re hoping to create.
Aloha Jim Bob,
I’m wondering, how would I add an anchor (#my_anchor) to the end of the link for Edit, Save, and Cancel? In a long list of items if I hit Edit the page refreshes and I have to scroll down to find what line I want to edit. This can be annoying even if it’s just a short scroll down.
Dear Rogue,
Great question. Answer: I don’t know.
There aren’t any answers to this question online—though it’s been asked numerous times—as far as I can find. GenFireServerEvent is a bit of a black boxto me, from which I must extrapolate theories by trial and error. ;)
But, this is SharePoint (a.k.a. “many ways to skin a cat”), and I DO know how you can get a similar result without the anchor…
In a CEWP, add jQuery to the page and have the last call inside $().document.ready() be:
$(”input[title='Your top-left-most column']“).focus();
Putting the focus there will scroll the page up for you.
That doesn’t help to bring that record back into view on Cancel, though. But, hopefully it will help the bulk of the frustration on this account.
Blessings,
Jim Bob