This project has moved and is read-only. For the latest updates, please go here.

SPFilterDropDown: Reverting on EditForm

Nov 1, 2012 at 1:20 PM

I have a single item edit DVWP working with SPFilterDropDown and SPGetCurrentUser. If it were a new item form, no problem. But, with the edit form, once the script runs, my multi-select lookup field "reverts": the things on the right move to the left.

List 1

  • People/Groups Field (returning Account): Person2
  • Calculated Field (returning text which shows an e-mail address): Subscription E-Mail

List 2

  • Title Field: Title
  • Multi-Select Lookup: Subscribers
  • Text Field (established by workflow - copy of ID value - used since "ID" can be funky as a query string variable): IID

As a user, I see an item in List 2, select a Subscribe button (just text on DVWP), and see a page that displays just a querystring-filtered editform with the Subscribers field. The field is a multi-select lookup to a big old list of e-mail addresses but, courtesy of the SPFilterDropDown and SPCurrentUser scripts, I just see my e-mail address on the left (unsubscribed) or on the right (subscribed).

However, right now, when the scripts run, my e-mail address flies over to the left side no matter the current value - not a problem on a newform but a mild problem on an editform.


(This is a proof of concept - in production, I aim to create a third list that "houses" the subscriptions - I have separate lists for discussions, responses, and comments but they all share a Discussion-ID value - if I get this to work, I can have a subscription model that bypasses OOTB alerts.)

Nov 1, 2012 at 1:24 PM
Edited Nov 1, 2012 at 1:25 PM

The code would help:

    $(document).ready(function() {

var thisUserAccount = $().SPServices.SPGetCurrentUser({
	fieldName: "Name",debug: false});

relationshipList: "{BC8B39D8-2567-4EE9-B73A-2598C18BA823}", 
relationshipListColumn: "Subscription_x0020_E_x002d_Mail",  
columnName: "Subscribers",  
listName: "{2996F581-6CAE-466A-BD2C-C9F4B5465ABD}",  
noneText: "(None)",  
CAMLQuery: "<Eq><FieldRef Name='Person2'/><Value Type='User'>"+thisUserAccount+"</Value></Eq>",  
completefunc: null,  
debug: true

Nov 1, 2012 at 1:42 PM

Originally deployed with 6.2 - same result with SPServices 7.2 and jQuery 8.2.

Nov 1, 2012 at 2:18 PM

Have you ever thought of having a different script for your edit form?  Instead of running all of these functions on your edit form, you could simply find the Subscriptions in the DOM and remove all of the unnecessary emails from the left instead.  You could use something similar to:

var $subscriptionOptions = $("select[title='Subscribers possible values']").find("option").filter(function(e){
	return this.title !== "25 - Created by moi"; //or an email addy.

That should work if you are wanting to trim the options to leave just the one email address.  Since it will *not* be present in the *possible values* control, all of the options will simply be removed from the DOM.



Nov 4, 2012 at 3:09 PM

Thank you - I hadn't. What you posted makes sense - and it would probably make the form behave more gracefully - and I've been playing around with the code on the form - but I don't quite know enough to make it work. This is for a pet project (read: non billable) so it's just me and a co-worker without solid javascript skill.