2

Situation: Attempting to create a conference room calendar. I've created a calendar and enabled resource reservation. A 'new event' form allows users to select resources (rooms in this case).

Question: Is it possible to have it so users can only select one resource? Or even do some type of data validation?

Unlike most lookup columns, I can't seem to modify the column setting to allow only single choice.

Thanks!

  • I have exactly the same requirement as yours. I'll work on it and get back here for what I'll have come up with – MdMazzotti Feb 7 '14 at 18:24
1

After some deep investigation, I can confirm the following:

  • the resource field (SPFieldFacilities) is a special type of SPFieldLookup (it derives from it) and the AllowMultipleValues flag is internally set to true and cannot be modified through the UI. It could be modified via PowerShell, and it would behave like a normal lookup field, but the Check Double Booking feature wouldn't work anymore.
  • if you only want to force it to allow only one selection (even though I believe that's not the full story and what you really need is to forcibly set it to some value...at least, this is my scenario, but I digress -I'll blog about this sooner or later), then the solution involves a hack as dirty as hell, which is hijacking one of the javascript function that takes care of handling the two select list boxes events (I'm referring to the two boxes next to the Add/Remove buttons)

The function to overwrite is GipAddSelectedItems and the following is the amended code you'll want to insert in the NewForm.aspx page, preferably inside the content place holder with ID PlaceHolderBodyAreaClass:

GipAddSelectedItems = function (master)
{ULSc04:;

// HACK *********************************************************
// remove all the selections from the box on the right
for(var i=0; i <  master.resultControl.options.length; i++){ 
    master.resultControl.options[i] = null;
}
//***************************************************************

var handler=master.addControl.getAttribute("onbeforeadd");
    if (handler !=null && handler !="")
    {
        if (!eval(handler+"(master)"))
            return;
    }
    var needToAdjustResultBox=false;
    if (master.resultControl.offsetWidth < master.candidateControl.offsetWidth)
    {
        needToAdjustResultBox=true;
    }
    var dirty=false;
    var pos=-1;
    for (var i=0; i < master.candidateControl.options.length; i++)
    {
        if (master.candidateControl.options[i].selected)
        {
            if (!dirty)
                pos=master.resultControl.length;
            master.resultControl.options[master.resultControl.length]=              GipNewOption(
                    master.candidateControl.options[i].text,
                    master.candidateControl.options[i].value);
            // HACK **********************************************************  
            // never remove items from the candidate box (the one on the left)
            //master.candidateControl.options[i]=null;
            dirty=true;
            // as we don't remove anything anymore, no need to decrement
            //i--;
            // ***************************************************************
        }
    }
    if (dirty)
    {
        GipSetHiddenControlValue(master);
        if (pos >=0)
        {
            master.resultControl.options[pos].selected=true;
            GipSelectResultItems(master)
        }
    }
    handler=master.addControl.getAttribute("onafteradd");
    if (handler !=null && handler !="")
    {
        eval(handler+"(master)");
    }
} 
  • This can by bypassed by holding shift when selecting. Is there a better solution? – Eitan K Jun 21 '16 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.