Bug with the LookupField control when the number of items is greater than 20
If the number of items is <= 20 then the control generate a DropDownList.
If the number of items is > 20 then the control generate a TextBox and an Image
When the LookupField has more than 20 items, we receive thew following error:
Microsoft JScript runtime error: Object required
The problem is raised in the Core.js file in the AbsLeft method.
| function AbsLeft(obj) |
| { |
| var x=obj.offsetLeft; |
| var parent=obj.offsetParent; |
| while (parent.tagName !="BODY") |
| { |
| x+=parent.offsetLeft; |
| parent=parent.offsetParent; |
| } |
| x+=parent.offsetLeft; |
| return x; |
| } |
The error is on "
while (parent.tagName !="BODY") ".
It appears that the loop never finds the BODY tag in the HTML document. I read on the Internet that this situation can occurs when using relative and absolute positionning within the CSS.
The best way I have found to make sure a lookup field is rendered as a normal dropdown, rather than that quirky thing SharePoint likes to insert, is to change the bound control in the XSL from "SharePoint:FormField" to "SharePoint:DVDropDownList".
You then have to add an extra data source to populate the dropdown options, but I've found this to be usefull too, since you can sort and filter the items in the list.
This is more like the traditional dropdown binding scenario - get the list of options from the lookup table and populate the selected choice from the proper field in the "main" table. The wierdo thing here is that the DVDropDownList control doesn't look as if it is bound to the "main" table (or, in this case, List) because of the esoteric syntax of the ddwrt:DataBind method.
Solution Steps:
1. Add a new "SharePoint:SPDataSource" to the web part that points to the list containing the lookup items
2. Replace the "SharePoint:FormField" control with a "SharePoint:DVDropDownList" (I just leave the old control and overwrite the element)
3. Change the appropriate element attributes (see code attachment)
4. Update the ddwrt:DataBind call to pull input from the new DVDropDownList control
5. ! Note that in ddwrt, "i" is for insert and "u" is for update
I hope this helps, as I know this is a frustrating problem. It's a rather ridiculous work-around, but that's SharePoint for you...
<!-- Here's the new SPDataSource for the lookup: -->
<SharePoint:SPDataSource
id="spdsRegions"
runat="server"
DataSourceMode="List"
UseInternalName="true"
selectcommand="<View></View>">
<SelectParameters>
<WebPartPages:DataFormParameter
Name="ListName"
ParameterKey="ListName"
PropertyName="ParameterValues"
DefaultValue="Regions"/>
</SelectParameters>
</SharePoint:SPDataSource>
<!-- This is the ORIGINAL control for comparison -->
<SharePoint:FormField
runat="server" id="ff11{$Pos}"
ControlMode="New"
FieldName="Regions"
__designer:bind="{ddwrt:DataBind('i',concat('ff11',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Regions')}" />
<!-- And here is the NEW control, which will render as a dropdown -->
<SharePoint:DVDropDownList
runat="server"
id="ff11{$Pos}"
DataSourceID="spdsRegions"
DataTextField="Title"
DataValueField="ID"
SelectedValue="{@Region}"
__designer:bind="{ddwrt:DataBind('i',concat('ff11',$Pos),'SelectedValue','SelectedIndexChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Region')}" />
<!-- Don't forget to change the 'i' in ddwrt:DataBind to a 'u' if this is an update rather than an insert form -->