Answered by:
Preventing Lookup columns from displaying input fields

Question
-
Hi,
I have a lookup field in a list. When there are less than 20 items, the form displays a <select> menu; over 20 items and it's an <input> field along with an image. Is there any way to prevent this. I want the <select> menu to display at all times regardless of how many items there are in the list. I know it does this with all non IE browsers.
Thanks in advance!
Wednesday, March 28, 2012 2:19 PM
Answers
-
Hi Burnsman,
It' a known issue, you can use javascript replace the custom dropdown control with a standard dropdown control. Following is a sample code with jquery:
function SwitchLookupsToCombos() { try { // loop all instances $('.ms-lookuptypeintextbox').each(function(i) { var comboInput = $(this); // hide input field $(comboInput).hide(); $(comboInput).next().hide(); //replace with normal select $(this).append('<select></select>'); var drop = $(this).find("select"); // add items var items = GetItems(); for(i=0;i<items.length;i++) { $(drop).append('<option value="'+items[i].ID+'">'+items[i].Name+'</option>'); } // add event to insert new select value into input field and hidden field $(drop).change(function(e) { var optHid = $(comboInput).attr('optHid'); $(comboInput).val($(this).find("option:selected").text()); $("input[name='"+optHid+"']").val($(this).val()); }); }); } catch(err) {} } /* objects */ function Item(id,name) { this.ID = id; this.Name = name; }
For more information, please refer to the following links:
http://www.mattkoon.net/articles/sharepoint/sharepoint-2007-disable-lookup-field-replacement-internet-explorer-20-or-more
http://microsoftsharepoint-dev.blogspot.com/2011/02/sharepoint-lookup-column-having.html
http://social.technet.microsoft.com/Forums/en-US/sharepointgeneral/thread/9ad56897-2fe7-4cfe-a2cc-c67dc4df5968/
https://spcd.codeplex.com/
Thanks,
Lhan Han
- Edited by Lhan HanModerator Tuesday, April 3, 2012 6:16 AM
- Marked as answer by Lhan HanModerator Tuesday, April 3, 2012 6:39 AM
Friday, March 30, 2012 7:33 AMModerator
All replies
-
Hi Burnsman,
It' a known issue, you can use javascript replace the custom dropdown control with a standard dropdown control. Following is a sample code with jquery:
function SwitchLookupsToCombos() { try { // loop all instances $('.ms-lookuptypeintextbox').each(function(i) { var comboInput = $(this); // hide input field $(comboInput).hide(); $(comboInput).next().hide(); //replace with normal select $(this).append('<select></select>'); var drop = $(this).find("select"); // add items var items = GetItems(); for(i=0;i<items.length;i++) { $(drop).append('<option value="'+items[i].ID+'">'+items[i].Name+'</option>'); } // add event to insert new select value into input field and hidden field $(drop).change(function(e) { var optHid = $(comboInput).attr('optHid'); $(comboInput).val($(this).find("option:selected").text()); $("input[name='"+optHid+"']").val($(this).val()); }); }); } catch(err) {} } /* objects */ function Item(id,name) { this.ID = id; this.Name = name; }
For more information, please refer to the following links:
http://www.mattkoon.net/articles/sharepoint/sharepoint-2007-disable-lookup-field-replacement-internet-explorer-20-or-more
http://microsoftsharepoint-dev.blogspot.com/2011/02/sharepoint-lookup-column-having.html
http://social.technet.microsoft.com/Forums/en-US/sharepointgeneral/thread/9ad56897-2fe7-4cfe-a2cc-c67dc4df5968/
https://spcd.codeplex.com/
Thanks,
Lhan Han
- Edited by Lhan HanModerator Tuesday, April 3, 2012 6:16 AM
- Marked as answer by Lhan HanModerator Tuesday, April 3, 2012 6:39 AM
Friday, March 30, 2012 7:33 AMModerator -
This is nice. One question... Where is GetItems() defined? This seems to be a key ingredient for this to work.Friday, October 25, 2013 12:34 PM