SPLookupAddNew

Nov 14, 2014 at 11:24 AM
Hi,

I'm using Office365 for development and I like what SPServices has to offer with the function SPLookupAddNew, but I hate the idea of constantly refreshing the webpage.

Is there a possibility to open the new lookup item as a popup? Changing the option for the lookup list did not affect SPServices.

Best regards,
Mariusz
Coordinator
Nov 14, 2014 at 12:47 PM
Mariusz:

I wrote SPLookupAddNew a long time ago, primarily to help me with debugging SPServices. I needed to add items to lists that made my test forms work in different ways.

It's certainly possible to make it work with a pop up. I originally wrote it for 2007, and with 2010, the excessive dialogs actually caused problems because the redirect back to the original form was problematic.

My suggestion would be to clone the function and make it work the way you want it to. If your enhancements seem like they could be of general use, please pitch them back!

M.
Nov 17, 2014 at 9:28 AM
Hi, Mark :-)

I'd love to participate in the development of SPServices :-)

I have a suggestion I'd like to discuss with you. Right now, SPServices.SPLookupAddNew has a parameter newWindow. Setting it to true opens a new tab/window which I believe is useless because of lack of callback capabilities. Changing the action of true value to opening a ModalDialog would actually make it more useful IMO.

Ofcourse, I cannot be sure, maybe someone made that an asset in their SharePoint apps or something and it wouldn't be cool to just replace that.
In that case I would just create a new boolean parameter.
What's your opinion on that matter?

Either way, the only remaining challenge would be to make a callback function that refreshes the lookup.

Best regards,
Mariusz
Nov 17, 2014 at 10:26 AM
Hello,

This could be done several ways. You could have a hidden dom element on the page that has an input tag for the user to add a new item to. You then add a mechanism such as a link or button that uses this hidden element in an SP.UI.ModalDialog window. You call the UpdateListItems method and then update the dropdown as needed. The UpdateListItems method will return a z:row with the ows_ID of the item (at least is has before and is documented as such).

Full Disclosure is that I was about to try to do this and that was my train of thought. You could use UpdateListItems or Javascript object model either way to update the lookup list.

Regards,

Dan
Nov 17, 2014 at 11:21 AM
spevilgenius wrote:
This could be done several ways. You could have a hidden dom element on the page that has an input tag for the user to add a new item to. You then add a mechanism such as a link or button that uses this hidden element in an SP.UI.ModalDialog window. You call the UpdateListItems method and then update the dropdown as needed. The UpdateListItems method will return a z:row with the ows_ID of the item (at least is has before and is documented as such).
I was thinking about that, but that would work only when the lookup has only the title. If the lookup looks up to a table with more columns a popup would be better.

Btw, Guys, if that's ok with you, I would do a small refactoring so the code is more managable. After it's done, you're code review would be appreciated :-)
Coordinator
Nov 17, 2014 at 12:53 PM
A complication arises because there is a form digest that prevents arbitrary values being added to the dropdowns. So if you add a new value and select it, you'll get an ugly error upon form submission. This is why I chose to send the user away and then return using the Source query string parameter.

M.
Nov 17, 2014 at 1:11 PM
My idea may not be the performance champion but it works, as far as I can tell.

On closing the popup that added new value to the lookup list I emptied the select, requested web services for all the values from the lookup and then just put them again in the select.

Some tests are needed, for example if the normal "no new window" option still works :-)

Mariusz