none
Add Blank value as default in lookup field RRS feed

  • Question

  • Hi,

    It might sound a trivial thing but I have invested lot of time in finding a solution for it ..

    I actually have a Lookup Field that gets the values from another list. This Lookup field is a mandatory field in my list however as per a requirement . I want a "BLANK VALUE" or Empty value to be shown as default and then user can select any value from dropdown.. all this need to be done using OOB features of moss..

    Any inputs on how to achieve the same ???
    • Moved by Lambert Qin [秦磊] Monday, September 1, 2008 3:04 AM only need OOTB feature solution (Moved from SharePoint - Design and Customization to SharePoint - General Question and Answers and Discussion)
    Thursday, August 28, 2008 12:34 PM

Answers

  • Hi, 

    I could understand your situation.

     

    I have a workaround that needs the help with SharePoint Designer 2007.

     

    1.    Locate the Lookup control use JavaScript.

    For detailed steps and the code samples, please refer to: Using JavaScript to Manipulate a List Form Field (http://blogs.msdn.com/sharepointdesigner/archive/2007/06/13/using-javascript-to-manipulate-a-list-form-field.aspx)


    2.   
    After you locate the control, you can use HTML Document Object Model (DOM) to add an option to the lookup field.

     

    I wish that someone has a better idea and you can share with us if you can find how to replicate the functionality

     

    Hope the information can be helpful.

    -lambert


    Posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, September 2, 2008 1:41 AM

All replies

  • Hi, 

    I am confused with your requirement.

     

    As you said the Lookup field was a mandatory field, and you want to a "Blank" or “Empty” value to be shown. The "Blank" or “Empty” value was one of the options that users could choose. If so, the mandatory field was useless.


    If the "Blank" or “Empty” value is just a notification to let users to select a value, I wonder if you can change it to “Please select” or other words.

     

    So, I suggest you to review and amend your business requirement.

     

     

    In case the requirement cannot be changed, the solution for your issue depends on the column which the Lookup field get information from.

    If the column is not a mandatory filed, you can add create an item in the source list with “Space” value.

     

    Hope the information can be helpful.

    -lambert


    Posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, September 1, 2008 3:02 AM
  • Hi Lambert,
    Sadly its difficult to change the business requirement. The client wants lookup [which is mandatory field] to hold a blank value which is displayed as soon as new form is opened. The problem here is that I cant put "Empty space" in field which is getting "Looked up" as it is also a mandatory field.

    The biggest setback here is that client people have shown us one of their portals where this is happening and we need to replicate the functionality in portals developed by us... And it seems disgraceful asking the client to tell us how they have implemented the same :)

    Regards
    • Edited by Bhavna B Monday, September 1, 2008 9:41 AM l added
    Monday, September 1, 2008 9:40 AM
  • Hi, 

    I could understand your situation.

     

    I have a workaround that needs the help with SharePoint Designer 2007.

     

    1.    Locate the Lookup control use JavaScript.

    For detailed steps and the code samples, please refer to: Using JavaScript to Manipulate a List Form Field (http://blogs.msdn.com/sharepointdesigner/archive/2007/06/13/using-javascript-to-manipulate-a-list-form-field.aspx)


    2.   
    After you locate the control, you can use HTML Document Object Model (DOM) to add an option to the lookup field.

     

    I wish that someone has a better idea and you can share with us if you can find how to replicate the functionality

     

    Hope the information can be helpful.

    -lambert


    Posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, September 2, 2008 1:41 AM
  • Actually there's merit in this question.  By creating a blank default field you essentially force the user to use the drop down list and choose something because the blank value is not an acceptable value.  I use it all the time with non-lookup fields, but unfortunately I'm in the same bucket now I also need to figure this out using lookup fields.

    Tuesday, January 13, 2009 11:31 PM
  • You can use JQuery to achieve your goal:

    var lookupFieldTitle = "Lookup Title"; var cmdSubmit = 'input[id$="_diidIOSaveItem"]'; $(document).ready(function() { var selectElement = $("td.ms-formbody select[title='" + lookupFieldTitle + "']"); selectElement.prepend('') .change(CheckSaveEnabling); selectElement.find('option:first-child').attr('selected','selected'); $(cmdSubmit).attr('disabled','disabled'); }); function CheckSaveEnabling() { var foundEmpty = false; $("td.ms-formbody select[title='" + lookupFieldTitle + "']").each(function () { var list = $(this); if (list.find('option:nth(' + list.get(0).selectedIndex + ')').text() == '') { foundEmpty = true; } }); if (foundEmpty) $(cmdSubmit).attr('disabled','disabled'); else $(cmdSubmit).removeAttr('disabled'); }

    You can refer to the following link.

    http://morshemesh.blogspot.com/2012/07/add-empty-option-to-mandatory-lookup.html


    Keith Tuomi | Twitter: @itgroove_keith | Blog: http://yalla.itgroove.net

    Please click "Propose As Answer" if a post solves your problem or "Vote As Helpful" if a post has been useful to you.

    Wednesday, February 20, 2013 10:02 PM
  • This worked for me.  I used the given code, except I changed

    selectElement.prepend('')

    to

    selectElement.prepend('<option value="0"></option>')

    Thanks!


    Chris Morelock



    • Edited by cjmore Tuesday, July 8, 2014 8:37 PM
    Tuesday, July 8, 2014 8:09 PM
  • Hi do I need to change anything in this code? 
    Thursday, July 25, 2019 2:41 PM
  • Just to chime in, we had observed inconsistent behavior on a few of our lists (with no code behind them) where some were showing the blank option on lookup fields and others weren't.

    After reading this post, I was able to deduce that the blank option was showing on the lists where the fields were marked as Required in the content type.

    After setting the list content type fields to optional, and by adding the Required flag to the columns directly from the List Settings page, the lookup values initially come up blank when loading the form, but the form validation will not allow the user to proceed until values are entered.

    Friday, August 23, 2019 2:49 PM