Use SPJS-Lookup in a customized form

Forums SPJS-Lookup Use SPJS-Lookup in a customized form

This topic contains 0 replies, has 1 voice, and was last updated by  Alexander Bautz 3 years, 6 months ago.

  • Author
    Posts
  • #6942

    Alexander Bautz
    Keymaster

    I generally do not support customized forms, but here is an small example on how to use this specific solution in a customized form.

    The example is not from a SharePoint form, and it is super simple to give you an idea on how you can set it up.

    DISCLAIMER: I cannot give any real support on this solution when used on a customized form.

    Use this code example in a web part page in your SharePoint site, and ensure you understand the code before trying it in a customized SharePoint form.

    <table>
    	<tr>
    		<td valign="top">Field 1</td>
    		<td valign="top" class="ms-formbody" id="myfield1">
    			<input type="text">
    		</td>
    	</tr>
    	<tr>
    		<td valign="top">Field 2</td>
    		<td valign="top" class="ms-formbody" id="myfield2">
    			<input type="text">
    		</td>
    	</tr>
    </table>
    
    
    <script type="text/javascript" src="/DFFS/SPJS/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="/DFFS/SPJS/SPJS-Utility/spjs-utility.js"></script>
    <script type="text/javascript" src="/DFFS/SPJS/SPJS_Lookup/SPJS-lookup.js"></script>
    <script type="text/javascript">
    
    spjs.lookup.intFields = function(){
    	var a = {};
    	spjs.$("td.ms-formbody").each(function(){
    		a[this.id] = this.parentNode;
    	});
    	spjs.lookup.data.fields = a;
    }
    
    spjs.lookup.init({
    	"fieldToConvertToDropdown":"myfield1",	
    	"listName":"Tasks",
    	"listBaseUrl":"",
    	"optTextFieldInternalName":"Title",
    	"sortFieldName":"Title",
    	"filterObj":{
    		"on":false,
    		"CAML":null, // If used, the rest of the filterObj settings are disregarded
    		"fin":"",
    		"isLookup":false,
    		"operator":"Eq",
    		"filterVal":""
    	},
    	"dropDownDefaultvalue":"...",
    	"addYouOwnValue":{
    		"on":true,
    		"linkText":"Write your own value"
    	},
    	"addToExternalList":{
    		"on":false,
    		"customFunction":null,
    		"linkText":"Add new item",
    		"saveNewItemText":"Save new item"
    	},
    	"debug":false
    });
    </script>

    The “magic” is done in the function “spjs.lookup.intFields” as this overrides the built in function in the spjs.lookup script.

    Alexander

You must be logged in to reply to this topic.