Sunday, November 11, 2012

Edit Form and New Form Dialog


Open a dialog model to edit current item and add new item to the list via DVWP sometimes is hard to do because of the returned values, and still, need to be modified by substring function or even more. However it can be executed by simple XSL and JS.
Define two parameters to send the as parameters to the function (considering the @FileDirRef returns 12;#/site/Lists/ListName for example):

<xsl:param name="FileURL" select="substring-after(@FileDirRef,';#')" />
<xsl:param name="FileURL2" select="concat('/',$FileURL)" />

wrap the value (title in this case) with <a> tag.

For edit:
<a href="#" onclick="javascript:openEditItemRisk({@ID},'{$FileURL2}')" ><xsl:value-of select="@Title"/></a>

For new item:
<a onclick="openNewItemRisk()">+ Create new item</a>

Attach JS file with this code:
function openNewItemRisk(){
    var options = {
    url: "../Lists/ListName/NewForm.aspx",
        allowMaximize: false,
        showClose: true,
        scroll: 0,
    dialogReturnValueCallback: silentCallbackNewForm};
    SP.UI.ModalDialog.showModalDialog(options);
}
function silentCallbackNewForm(dialogResult, returnValue) {
    location.reload();
}

function openEditItemRisk(currentId,url){
    var options = {
    url: url + "/EditForm.aspx?ID=" + currentId, //Can be changed to DispForm in order to only view the item
    allowMaximize: false,
    showClose: true,
    scroll: 0,
    dialogReturnValueCallback: silentCallbackEditForm};
    SP.UI.ModalDialog.showModalDialog(options);
}
function silentCallbackEditForm(dialogResult, returnValue) {
    location.reload();
}

No comments:

Post a Comment