› Forums › Classic DFFS › How to use setFieldValue with multiple choice lookup fields?
Tagged: choice, Javascript, setfieldvalue
- This topic has 9 replies, 2 voices, and was last updated 8 years, 6 months ago by
Alexander Bautz.
-
AuthorPosts
-
-
January 5, 2016 at 15:28 #9754
Michael Yarbrough
ParticipantHowdy. I have used the getFieldValue just fine with a multi choice lookup field, it returns an array and works well. However, if I pass an array of strings to the setFieldValue it doesn’t seem to work. Is there a means of doing this?
Thanks in advance!
-
This topic was modified 8 years, 6 months ago by
Michael Yarbrough.
-
This topic was modified 8 years, 6 months ago by
-
January 5, 2016 at 16:08 #9765
Alexander Bautz
KeymasterHi,
Which version of SharePoint are you using?You should be able to set multiple values like this:
setFieldValue("MultiLookup",["Option number 1","Option number 2"]);
“MultiLookup” = the FieldInternalName you want to set.
Alexander
-
January 5, 2016 at 16:43 #9770
Michael Yarbrough
ParticipantUsing SP 2013. I believe that is what I am doing, however, it doesn’t seem to be taking. I am thinking that I need to use Id’s of the options instead of the string names since it is a lookup, and perform a setFieldValue on the hidden Id column, like `setFieldValue(“MultiLookupId”,[“1″,”2”]);
Thoughts?
-
January 5, 2016 at 17:11 #9774
Michael Yarbrough
ParticipantTried this to no avail:
setFieldValue("Level_x0020_3_x0020_Org", ["GR PA", "SOUTH FLORIDA"]); console.log(JSON.stringify(getFieldValue("Level_x0020_3_x0020_Org")));
The getFieldValue still shows the original values, not the ones I am trying to set.
-
January 5, 2016 at 21:24 #9786
Alexander Bautz
KeymasterWhich version of spjs-utility.js are you using? – I have done some changes a few months back that may be relevant (current version is 1.257).
You can check in in the dev console by typing in
spjs.utility.version
Alexander
-
January 5, 2016 at 21:29 #9790
Michael Yarbrough
ParticipantWe are on 1.255. I have tried setting the ids instead of the names of the lookup values as well but that does not work either. I am able to update the lookup fields through a REST call, which will work, except that when the save on the form is called I get a conflict error stating someone has made changes to the form since it was last opened.
-
January 5, 2016 at 21:42 #9798
Alexander Bautz
KeymasterCould you try using the latest version from the BETA version of DFFS: https://spjsblog.com/dffs/dffs-installation-manual/#Download_the_files
My code example above was tested in my form and it works so I cannot see why it should not work in your setup.
Alexander
-
January 5, 2016 at 21:47 #9802
Michael Yarbrough
ParticipantWe may be able to get the latest version and test. Just to be sure I am testing correctly, if I do this I should be able to set it and see the new values before a save, correct?
In the development console. North Florida and West Florida are valid values in my lookup list:
setFieldValue("Level_x0020_3_x0020_Org", ["NORTH FLORIDA", "WEST FLORIDA"]); console.log(JSON.stringify(getFieldValue("Level_x0020_3_x0020_Org")));
-
January 5, 2016 at 21:52 #9804
Michael Yarbrough
ParticipantSo, in my testing this seems to work:
setFieldValue("Level_x0020_3_x0020_Org", "NORTH FLORIDA,WEST FLORIDA", false);
However, it appends instead of replaces the existing values. Is there an documentation on the options and usage of setFieldValue?
Getting close!
-
January 5, 2016 at 22:04 #9806
Alexander Bautz
KeymasterSorry, but there are no documentation on this one.
The default functionality is to add to the selection, and not replace. You can however override it by creating a new function like this in your Custom JS in DFFS backend (this is the original code):
spjs.utility.setFieldValue_SPFieldLookupMulti = function(a){ setTimeout(function(){ var f = spjs.$(spjs.utility.data.fields[a.fin]), lId, type = spjs.utility.verifyLookupFieldType(a.fin); if(type !== "" && typeof spjs.utility["setFieldValue_SPFieldLookupMulti"+type] === "function"){ spjs.utility["setFieldValue_SPFieldLookupMulti"+type](a); return; } if(f.find('select:first option:first').prop('spjs') !== "1"){ f.find('select:first option:first').prop('selected', false); } if(!spjs.$.isArray(a.newVal)){ if(typeof a.newVal === "string"){ a.newVal = a.newVal.split(","); }else{ a.newVal = [a.newVal]; } } spjs.$.each(a.newVal,function(i,val){ if(typeof val === "object"){ lId = String(val.get_lookupId()); }else{ lId = String(val); } if(String(parseInt(lId,10)) === String(lId)){ f.find('select:first').find("option").filter(function() { return spjs.$(this).val() === lId; }).prop('selected', true); }else{ f.find('select:first').find("option").filter(function() { return spjs.$(this).text() === lId; }).prop('selected', true); } }); f.find(":button:first").trigger("click"); spjs.utility.updateReadonlyValue(a); },1000); }
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.