Dialog

Contents:

Intro

Dialog can be used to open other forms in dialog from a parent form. Can open multiple dialogs at the same time, but only the last one will be active. Can also open forms in dialog from other forms opened in dialog.

Note: This property is exclusive to SharePoint Forms.

Methods

These methods are applicable to most fields:

Method Description/Examples
open(url, arguments, callback(bool, args))

Opens form in dialog.

url - url to open in dialog (only works for URLs on the same domain).

arguments - JS object to pass arguments to the form opened in dialog.

callback(bool, args) - function called when dialog is closed. Takes two parameters:

  • bool - returns true if the form in dialog was saved,
  • args - JS object which can be used to pass arguments from the closing form (need to use Dialog.close(bool, args)).

Example:

Dialog.open("https://mycompany.sharepoint.com/sites/mysite/_layouts/15/listform.aspx?PageType=8&ListId=" + listId,
    { args: 'something' }, function(hasSaved) {
    if(hasSaved){
        alert('Form in dialog has saved and closed.');
    }
    else{
        alert('Dialog form was closed without saving!');
    }
});

Read more about generation of form URLs here.

getArgs()

Get arguments passed to a dialog.

Can be called from both parent and child form, but generally more useful on child form.

On parent form, returns arguments passed to the last opened dialog form.

On child form, returns arguments passed to the this dialog form.


Example:

//code for Parent Form to pass New Title
Dialog.open("https://mycompany.sharepoint.com/sites/mysite/_layouts/15/listform.aspx?PageType=8&ListId=" + listId,
    { passedTitle: 'New Title' });

//code for Child Form to retrieve New Title
fd.spRendered(function() {
    //if opened in dialog
    if (window.frameElement && Dialog.getArgs()){
        //set Title to passedTitle property
        fd.field("Title").value = Dialog.getArgs().passedTitle;
    }
});

Read more about generation of form URLs here.

close(bool, args)

Close dialog form.

Can be called from both parent and child form.

On parent form, closes the last active dialog form.

On child form, closes this specific dialog form.


Example:

//code for Parent Form to show created Item ID in alert
Dialog.open("https://mycompany.sharepoint.com/sites/mysite/_layouts/15/listform.aspx?PageType=8&ListId=" + listId,
    { args: 'something' }, function(hasSaved, returnedArgs) {
    if(hasSaved){
        alert('Form in dialog has been saved. New Item ID: ' + returnedArgs.ID);
    }
    else{
        alert('Dialog form was closed without saving!');
    }
});

//code for Child Form to pass ID after save
fd.spSaved(function(result) {
    //if opened in dialog
    if (window.frameElement && Dialog.getArgs()){
        Dialog.close(true, {ID: result.Id });
    }
});

Read more about generation of form URLs here.