none
LookupMulti Custom Field

    Question

  •  

    Hello,

     

    I'm trying to create a custom field type that would function in the same way as MultipleLookupField does, except that in edit mode it would display the autocomplete textbox with multiple item selection capabilities.

     

    I cannot make it to save SPFieldLookupValueCollection correctly, only the first selected value is always saved.

     

    Here is my xml:

    Code Snippet

    <FieldTypes>

    <FieldType>

    <Field Name="TypeName">AutoComplete</Field>

    <Field Name="ParentType">LookupMulti</Field>

    <Field Name="TypeDisplayName">AutoComplete</Field>

    <Field Name="TypeShortDescription">AutoComplete textbox</Field>

    <Field Name="UserCreatable">TRUE</Field>

    <Field Name="Sortable">FALSE</Field>

    <Field Name="Filterable">TRUE</Field>

    <Field Name="SQLType">int</Field>

    <Field Name="FieldEditorUserControl">/_controltemplates/AutoCompleteFieldEditControl.ascx</Field>

    <Field Name="FieldTypeClass">BlueBridge.Sharepoint.CustomFields.AutoCompleteField, CustomFields</Field>

    <PropertySchema>

    <Fields>

    <Field Name="ListInterval" DisplayName="ListInterval" Hidden="TRUE" Type="Integer"/>

    <Field Name="ItemsToDisplay" DisplayName="ItemsToDisplay" Hidden="TRUE" Type="Integer"/>

    <Field Name="MinimumPrefixLength" DisplayName="MinimumPrefixLength" Hidden="TRUE" Type="Integer"/>

    <Field Name="EnableAnimations" DisplayName="EnableAnimations" Hidden="TRUE" Type="Boolean"/>

    <Field Name="IsMultiline" DisplayName="IsMultiline" Hidden="TRUE" Type="Boolean"/>

    <Field Name="NewLineAsDelimiter" DisplayName="NewLineAsDelimiter" Hidden="TRUE" Type="Boolean"/>

    <Field Name="DelimiterCharacters" DisplayName="DelimiterCharacters" Hidden="TRUE" Type="Text"/>

    </FieldType>

    </FieldTypes>

     

     

    The GetValidatedString method returns all the value/text pairs, separated by ";#". And however, only the first one is saved.

    I have the field's AllowMultipleValues property overriden, it always returns true.

    Control's Value property returns SPFieldLookupValueCollection with all items in it.

    Am I missing something? I cannot believe custom multiple lookup fields cannot be created, but find no ways to make it work.

     

    By the way, if I used SPFieldText instead of SPFieldLookup, would it be possible to make it function like a lookup field? I need that selected values would be displayed as links in the AllItems view at least. In what format should the values be saved? What CAML should i use in the RenderPattern?

     

    Thank you for your help,

     

    Donatas

     

     

    Thursday, May 22, 2008 3:31 PM

All replies

  • I am trying to do the same thing you are, but I am running into trouble before I even get to the point of trying to save multiple values.  When ever I set a ParentType of LookupMulti my field edit control gets left in the dust and the field becomes a lookup instead of my custom lookup.

     

    I was wondering if you ran into any of these problems and if you were ever able to get some of your other questions answered?

     

    Thanks,

    Peter

     

     

    Thursday, June 26, 2008 2:11 PM
  • I have the same problem.
    Do you find a solution ?
    Wednesday, August 6, 2008 12:07 PM
  • And I am also trying to figure out how to do this... Tried everything, looked everywhere. Is it actually possible to customize a LookupMulti field?

    Rodrigues
    Monday, September 15, 2008 1:37 PM
  • Hi.

    Any pointers on this issue would be most appreciated.

    Cheers,
    JC
    Thursday, October 2, 2008 11:56 AM
  • Hi everybody

    Unfortunately the issue could well be different in all your cases so it's going to be hard to give an easy answer to this.

    Firstly, a bit of code in the actual Field Control - and any custom field value classes would be useful. Have you created a class for the Field Control as well? What value do you get from the Value property? Have you been able to step through your code and find out what is going on inside, and most importantly what the classes are doing with the values selected by the users and how they are being persisted to the underlying field.

    The answer could well be a simple one, but more specific information is required in order to nail it down.

    If you could let me know what you have, how it is meant to work and then it might make the process a bit easier.

    Stu

    Thursday, October 2, 2008 12:40 PM
  •  

    Hello,

     

    I'm trying to create a custom field type that would function in the same way as MultipleLookupField does, except that in edit mode it would display the autocomplete textbox with multiple item selection capabilities.

     

    I cannot make it to save SPFieldLookupValueCollection correctly, only the first selected value is always saved.

     

    Here is my xml:

    Code Snippet

    < FieldTypes >

    < FieldType >

    < Field Name = " TypeName " > AutoComplete </ Field >

    < Field Name = " ParentType " > LookupMulti </ Field >

    < Field Name = " TypeDisplayName " > AutoComplete </ Field >

    < Field Name = " TypeShortDescription " > AutoComplete textbox </ Field >

    < Field Name = " UserCreatable " > TRUE </ Field >

    < Field Name = " Sortable " > FALSE </ Field >

    < Field Name = " Filterable " > TRUE </ Field >

    < Field Name = " SQLType " > int </ Field >

    < Field Name = " FieldEditorUserControl " > /_controltemplates/AutoCompleteFieldEditControl.ascx </ Field >

    < Field Name = " FieldTypeClass " > BlueBridge.Sharepoint.CustomFields.AutoCompleteField , CustomFields </ Field >

    < PropertySchema >

    < Fields >

    < Field Name = " ListInterval " DisplayName = " ListInterval " Hidden = " TRUE " Type = " Integer " />

    < Field Name = " ItemsToDisplay " DisplayName = " ItemsToDisplay " Hidden = " TRUE " Type = " Integer " />

    < Field Name = " MinimumPrefixLength " DisplayName = " MinimumPrefixLength " Hidden = " TRUE " Type = " Integer " />

    < Field Name = " EnableAnimations " DisplayName = " EnableAnimations " Hidden = " TRUE " Type = " Boolean " />

    < Field Name = " IsMultiline " DisplayName = " IsMultiline " Hidden = " TRUE " Type = " Boolean " />

    < Field Name = " NewLineAsDelimiter " DisplayName = " NewLineAsDelimiter " Hidden = " TRUE " Type = " Boolean " />

    < Field Name = " DelimiterCharacters " DisplayName = " DelimiterCharacters " Hidden = " TRUE " Type = " Text " />

    </ FieldType >

    </ FieldTypes >

     

     

     

     

    The GetValidatedString method returns all the value/text pairs, separated by ";#". And however, only the first one is saved.

    I have the field's AllowMultipleValues property overriden, it always returns true.

    Control's Value property returns SPFieldLookupValueCollection with all items in it.

    Am I missing something? I cannot believe custom multiple lookup fields cannot be created, but find no ways to make it work.

     

    By the way, if I used SPFieldText instead of SPFieldLookup, would it be possible to make it function like a lookup field? I need that selected values would be displayed as links in the AllItems view at least. In what format should the values be saved? What CAML should i use in the RenderPattern?

     

    Thank you for your help,

     

    Donatas

     

     

    Hi, Donatas.
    Have you fixed that error in your field?
    I am running into a same problem like yours now. Can you give me some tips?
    Tuesday, December 29, 2009 10:18 AM
  • Hi,

    I had the same issue, but found a solution for that. Not very nice, but it works at least. Call that workaround if you wish.

    Include the following code in the field class:

    using System.Reflection;

    ...

    private void SetFieldAttributeValue_Internal(string attrName, string attrValue)
    {
        Type baseType = GetType().BaseType;
        Object result = baseType.InvokeMember("SetFieldAttributeValue",
            BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance,
            null, this, new object[] { attrName, attrValue });
    }

    public override bool AllowMultipleValues
    {
        get
        {
            return base.AllowMultipleValues;
        }
        set
        {
            base.AllowMultipleValues = value;

            SetFieldAttributeValue_Internal("Type", "YourFieldType");
        }
    }

    Source:
    WSS 3.0 SPField derrived classes
    http://willemboere.blogspot.com/2007/04/wss-30-spfield-derrived-classes.html

    See the comments section.

    Thanks go to Alex Hekstra!

    Peter

    Wednesday, January 27, 2010 10:33 PM
  • Hi,

    Or may be better to apply this hotfix:

    Description of the Windows SharePoint Services 3.0 Cumulative Update Server hotfix package (Sts-x-none.msp): December 15, 2009
    http://support.microsoft.com/default.aspx/kb/977022/

    "You develop a custom field type that inherits from the SPFieldLookUp class. You want to store multiple values in a field of that custom field type. Therefore, you set the AllowMultipleValues property to True. However, after you set the AllowMultipleValues property to True, the field type is displayed as Lookup instead of the custom field type."

    Peter
    Wednesday, January 27, 2010 10:43 PM
  • does anyone have a solution for the original question? i'm having the same problem - a custom Multiple Lookup field type that only ever saves one value

    donatas, 2 years is a long time to be exposed to sharepoint and not kill yourself but is there any chance you're still around and have a solution?

    Friday, August 27, 2010 6:49 PM