Overview
I have a CustomAction for a button on the ribbon that calls a command in a javascript file. The command fails in the inplview.debug.js file on the following lines (1745 - 1748) in the GetFocusInfo method:
while((focusBack.tagName !="A") && (focusBack.tagName !="BODY"))
{
focusBack=focusBack.parentNode;
}
The problem is on the 2nd iteration, focusBack is null. I assume something about the event I'm passing is wonky. If I call the method directly from the javascipt console, it executes correctly.
I eventually gave up and used window.SP.UI.ModalDialog.showModalDialog({url:this.url});
But I'm still curious as to what's going on here. Maybe it's more appropriate as a general javascript question on stackoverflow.
Here is my custom action:
<CustomAction
Location="ScriptLink"
ScriptSrc="/_layouts/ASAP/CustomActions.js"
Sequence="1100" />
<CustomAction
Id="NewSupplementalDocument"
Location="CommandUI.Ribbon"
RegistrationType="ContentType"
RegistrationId="0x0100C44D4F1333A44FC9893DC3CFC16541A0"
Sequence="1200" >
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.ListItem.Actions.Controls._children">
<Button Id="Ribbon.ListItem.Actions.GISRowSupplemental"
Alt="Supplemental Button"
Sequence="5"
Command="New_Supplemental"
labelText="New Suppl"
ToolTipTitle="Add a suplemental document to this GIS row."
Image32by32="/_layouts/1033/images/formatmap32x32.png"
Image32by32Top="-320"
Image32by32Left="-64"
TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler Command="New_Supplemental"
CommandAction="javascript:
SP.SOD.executeOrDelayUntilScriptLoaded (LoadCoreAndGo,'sp.js');">
</CommandUIHandler>
</CommandUIHandlers>
</CommandUIExtension>
Here is my javascript file:
var inProgress = false;
var listName = 'GIS Row Supplemental Documents';
var list;
var url;
function LoadCoreAndGo() {
window.SP.SOD.executeOrDelayUntilScriptLoade
(GotoSupplementalNewFormUrl, 'Core.js');
}
function GotoSupplementalNewFormUrl() {
if (!inProgress) {
try {
inProgress = true;
var context = new SP.ClientContext.get_current();
var web = context.get_web();
this.list = web.get_lists().getByTitle(listName);
context.load(this.list, 'Id');
context.executeQueryAsync(Function.createDelegate(this,success),
Function.createDelegate(this, fail));
}
catch(e) {
alert(e);
inProgress = false;
}
}
}
function success() {
try {
var id = String(this.list.get_id());
this.url = '/_layouts/Upload.aspx?List={' + id.toUpperCase() + '}';
window.NewItem2(event, this.url); <-- This is where it fails
}
catch (e) {
alert(e);
}
finally {
inProgress = false;
}
}
function fail(sender, args) {
alert('Operation failed: ' + args.get_message());
inProgress = false;
}
Any ideas on what the issue might be?