Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

A lot of my Sharepoint Sites require input from the Users to add to Lists, Document Libraries and so on. However, sometimes Users have trouble finding the "Add New Item" button when attempting to add to a list.

I've gotten around the issue by simply adding a more visible button to the page (via HTML) which links directly to the NewForm.aspx page for my List. This gets the job done, but I'd rather have the NewForm appear as a Pop-Up window like it would when clicking the actual "Add New Item" button.

Is there a way to implement the Add new item Pop-Up form into my HTML code? Perhaps with Javascript perhaps?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Yes you can call the SP JavaScript library to open up the modal pop up.

$('.button').click(function (e) {
        e.preventDefault();
        var options = SP.UI.$create_DialogOptions();
        options.url = $(this).attr("href"); //url of the newitem.aspx
        options.dialogReturnValueCallback = Function.createDelegate(null, processClose);
        SP.UI.ModalDialog.showModalDialog(options);
    });

    function processClose(result, returnValue) {
        if (result == SP.UI.DialogResult.OK) {
            if (returnValue == null) {
                SP.UI.Notify.addNotification('Operation successful');
                SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
            }
        }
    }

This code above will open the modal dialog and handle closing of it. Also i am using jquery, so make sure you have that referenced in the page.

share|improve this answer
    
A good article on this subject: blog.lekman.com/2010/06/working-with-sharepoint-2010-modal.html –  Emon Feb 27 '13 at 0:27
    
This worked perfect, thanks! –  Lando Feb 27 '13 at 17:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.